Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Having issues with simple serial communication.

Hi,

I have optics module which communicate on serial bus. I am using Visa serial bus to talk to it.

 

Bus Frame is like this 

 

1. Start of header  : 1 byte

2. Address : 1 byte

3. Command :1byte

4. Data length: 1 Byte

5. Data: 0-255 Bytes

6. Checksum: 2bytes

 

I have to send command in hex format , and visa serial bus takes string to write it to the port.

i am not able to communicate with the module.

 

 

Checksum Computation

If the following frame needs to be transmitted: 0xF4, 0x41, 0x20, 0x00 the checksum should be as follows:

  1. 0xF4 + 0x41 + 0x20 + 0x00 = 0x0155
  2. Take the 1’s compliment of that value: 0xFEAA
  3. Append the new checksum to the end of the frame: 0xF4, 0x41, 0x20, 0x00, 0xAA, 0xFE
0 Kudos
Message 1 of 4
(2,976 Views)

On mobile, so I cannot see your code.  But my blind advice is to build your message using an array of bytes.  You will need to convert to U16 for the checksum, split the result into 2 U8, and the build array to add the 2 bytes.  Then use Byte Array To String, which then goes to the VISA Write.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 4
(2,963 Views)

Try this, I modified your code with 2 checksum methods.

It's tricky; I blame the documentation, if they would only provide a few data word examples with checksum so we programmers can test our routines on 'known' messages.

Also, what the 'sum' constitutes can be a variable, some systems only checksum the payload of the message and not the entire address and header bytes.

 

It's more error than trial.

Regards

Jack Hamilton

Message 3 of 4
(2,949 Views)

Thanks for the reply. I was able to get it work with you code. Had to twig my hardware one IC had gone bad.

 

0 Kudos
Message 4 of 4
(2,903 Views)