RS232 Help please

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

RS232 Help please

Post 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 ?
visi-commands.png
(72.91 KiB) Downloaded 4708 times
visi-write.png
(62.26 KiB) Downloaded 4708 times
thanks in advance
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post 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.
4dthread.png
(23.43 KiB) Downloaded 4680 times
Thanks in advance
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post by acestu »

Hi,

I found this bit in one of the PDF files:
checksum.png
(19.37 KiB) Downloaded 4671 times
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
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post by acestu »

Hi,

I have found this piece about the checksum, however I don't understand it could somebody please help me with it ?
checksumExp.png
(9.57 KiB) Downloaded 4670 times
What does XOR ing mean ?

thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: RS232 Help please

Post 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)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post by acestu »

Hi Kersing,

Thanks for the info, I will experiment somewhat and see if I can calculate it correctly :D

cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post 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
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: RS232 Help please

Post 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
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post 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... :oops:

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
checksum.fcfx
(4.79 KiB) Downloaded 281 times
cheers
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: RS232 Help please

Post 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.
Attachments
checksum.fcfx
(6.58 KiB) Downloaded 273 times
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post 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... :D

P.S. I cannot open your posted chart it says:
arraynotfound.png
(9.23 KiB) Downloaded 4618 times
Thanks
Acestu
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: RS232 Help please

Post by kersing »

You need to download the update to flowcode 6.0.2. Use the menu: 'Help', 'Check for updates'.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post 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
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: RS232 Help please

Post by kersing »

Notice I also added 0x to the 3 and 15 in the calculation.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 783 times
Been thanked: 223 times

Re: RS232 Help please

Post 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
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

Post Reply