Page 1 of 1
RS232 Help please
Posted: Sat Sep 28, 2013 5:37 am
by acestu
Hi,
I want to use the RS232 component to send data to a Visi display, the protocol is: 8 Bits, No Parity, 1 Stop Bit. I have searched for a demo but cannot find one, basically I wanted to know how you send your data in the component macro, as in do you use the send character a number of times or do you use the send string?
This would be the structure of the information but how do you send it ?
thanks in advance
Acestu
Re: RS232 Help please
Posted: Sat Sep 28, 2013 2:04 pm
by acestu
Hi,
I have posted a thread on the 4D forum asking why all of the example boxes in the Visi Enviroment Reference manual are just blank, however they could not tell me anything of any use, they said try the user manual but it dosen't mention anything, also he said that most of the info is Arduino related, so if anybody could give me any pointers I would be most grateful.
Thanks in advance
Acestu
Re: RS232 Help please
Posted: Sat Sep 28, 2013 9:39 pm
by acestu
Hi,
I found this bit in one of the PDF files:
I understand the command, object id, object index, but not sure what the MSB and LSB are and how is the checksum calculated ?
P.S. how are the numbers put into the rs232 component ?, I am guessing that you use send or receive string then put in your numbers separated by commas ?
Thanks
Acestu
Re: RS232 Help please
Posted: Sat Sep 28, 2013 9:54 pm
by acestu
Hi,
I have found this piece about the checksum, however I don't understand it could somebody please help me with it ?
What does XOR ing mean ?
thanks
Acestu
Re: RS232 Help please
Posted: Sat Sep 28, 2013 10:07 pm
by kersing
XOR is exclusive OR. The C operator is ^ (Flowcode knows XOR in calculations)
Truth table is:
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
For checksum start with 0, then for every byte (including CMD) you send to the display use
checksum = checksum XOR output_byte
After all other bytes have been send, send checksum. Do NOT use above formula on this byte when sending.
MSB = Most significant byte
LSB = Least significant byte
Any value > 256 needs two bytes to send it. for MSB divide value by 256. (MSB = value / 256) For LSB take remainder of division by 256. (LSB = value % 256)
Re: RS232 Help please
Posted: Sat Sep 28, 2013 10:20 pm
by acestu
Hi Kersing,
Thanks for the info, I will experiment somewhat and see if I can calculate it correctly
cheers
Acestu
Re: RS232 Help please
Posted: Sun Sep 29, 2013 12:28 am
by acestu
Hi,
I am really struggling with this.
In the diagram above I am trying to workout how they get the 16 checksum from this 0704000015 ?
If anybody could just write how this calculation is done I would be most grateful, I have been searching google all night but my findings are getting more complicated
cheers
Acestu
Re: RS232 Help please
Posted: Sun Sep 29, 2013 11:43 am
by kersing
All values are hexadecimal, so 2 digits (A-F are digits as well) are one byte, to calculate the checksum just start with zero and start XORring the values:
Code: Select all
checksum = 00
checksum = 00 XOR 07 = 07 (0000 0000 XOR 0000 0111 = 0000 0111)
checksum = 07 XOR 04 = 03 (0000 0000 XOR 0000 0100 = 0000 0011)
checksum = 03 XOR 00 = 03 (0000 0011 XOR 0000 0000 = 0000 0011)
checksum = 03 XOR 00 = 03 (0000 0011 XOR 0000 0000 = 0000 0011)
checksum = 03 XOR 15 = 16 (0000 0011 XOR 0001 0101 = 0001 0110)
Result: checksum = 16
Re: RS232 Help please
Posted: Sun Sep 29, 2013 5:54 pm
by acestu
Hi Kersing,
As you said that Flowcode calculations understand the ^ operator I have put a chart together to calculate 03 XOR 15 which is the last line of your above example but instead of giving the answer 16 it gives me 12, so I have done something wrong somewhere...
EDIT: Is it something to do with Decimal numbers that should be Hex in the calculation ? I think I have got to convert from base -16 to base -2 first
cheers
Acestu
Re: RS232 Help please
Posted: Sun Sep 29, 2013 7:54 pm
by kersing
You are right, the numbers are all hexadecimal (hex), not decimal. When you use 0x in front of the numbers (0x03 and 0x15) flowcode will interpret them as hex (and so will the compilers).
There is no need to convert the numbers to base-2, just use '0x' in front of what you find in the documentation. If you want to convert them (for your readability and to understand what happens) use 0b in front of the number to tell flowcode it is binary (base-2)
Attached an updates version of your example.
Re: RS232 Help please
Posted: Sun Sep 29, 2013 8:27 pm
by acestu
Hi Kersing,
Things are starting to make a little more sense now, I thought there must of been a way of declaring to Flowcode what base your numbers are in, I have never done any coding you see, which is why I use Flowcode, but it is really interesting to learn what is under the bonnet, thanks for your help and I will continue to dabble with this subject until it is clear...
P.S. I cannot open your posted chart it says:
Thanks
Acestu
Re: RS232 Help please
Posted: Sun Sep 29, 2013 9:10 pm
by kersing
You need to download the update to flowcode 6.0.2. Use the menu: 'Help', 'Check for updates'.
Re: RS232 Help please
Posted: Sun Sep 29, 2013 10:10 pm
by acestu
Hi Kersing Wow I just opened your chart and the first thing I saw was
"Remember the printed answer is decimal" so 22 is right just in the wrong base, that explains a lot...
Thanks again Kersing
Acestu
Re: RS232 Help please
Posted: Sun Sep 29, 2013 10:39 pm
by kersing
Notice I also added 0x to the 3 and 15 in the calculation.
Re: RS232 Help please
Posted: Sun Sep 29, 2013 10:53 pm
by acestu
Hi Kersing,
To be honest, I had done that but I was still getting 22 so I thought it was still wrong, it all made sense when you said that the printed number was Decimal, I am just trying to write a chart now that will let me put all the numbers in via a keypad then workout hopefully the checksum.....
cheers
Acestu