Serial inputs on Advanced Module

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Post Reply
Dave @Harper Adams
Posts: 33
Joined: Tue May 21, 2013 4:21 pm
Been thanked: 1 time
Contact:

Serial inputs on Advanced Module

Post by Dave @Harper Adams »

Hi

I am wanting to read the serial data put out from several sensors.
The data is in the form of a 34 byte message ( H xxxxx T xxxxx Z xxxxx z xxxxx\r\n).
I can read the data thyrough the Serial Module but not on the Advanced Module. on the advanced Module it only reads the first 6 bytes, and it does not always read it.
I have attached my Flowcode for both the Serial and Advanced Modules (the only changes between the two are the connection for the serial component). I have also enclosed .CSV files of the logged serial information.
Any ideas?

Regards Dave
Attachments
CO2 sensor reader 2 - advanced.fcf
(12.5 KiB) Downloaded 304 times
CO2 sensor reader 2 - serial.fcf
(12.5 KiB) Downloaded 304 times

Dave @Harper Adams
Posts: 33
Joined: Tue May 21, 2013 4:21 pm
Been thanked: 1 time
Contact:

Re: Serial inputs on Advanced Module

Post by Dave @Harper Adams »

I don't appear to be able to attach the .CSV files

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Serial inputs on Advanced Module

Post by JohnCrow »

Hi Dave
The forum software blocks certain file types as a direct upload (not sure about CSV files), but you can always zip them and upload that way.
1 in 10 people understand binary, the other one doesn't !

Dave @Harper Adams
Posts: 33
Joined: Tue May 21, 2013 4:21 pm
Been thanked: 1 time
Contact:

Re: Serial inputs on Advanced Module

Post by Dave @Harper Adams »

Thanks John

Attached are the zipped up log files

Regards Dave
Attachments
RS232 Serial-Advanced logs.zip
(307 Bytes) Downloaded 303 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Serial inputs on Advanced Module

Post by LeighM »

Hi,
A few of things you could try:
Add a delay, say 500mS, to the start code before you initialise the expansion modules, just to ensure they are powered up before attempting to write to them.
Try increasing the ReceiveRS232String Timeout value to 250 (the Timeout value is 8 bit char so 650 will actually give you 138)
Try using ReceiveRS232Char in a count loop to receive your string, instead of ReceiveRS232String which fetches 6 bytes at a time. (The Char macro returns 0x2f for timeout)
Hope that helps
Leigh

Dave @Harper Adams
Posts: 33
Joined: Tue May 21, 2013 4:21 pm
Been thanked: 1 time
Contact:

Re: Serial inputs on Advanced Module

Post by Dave @Harper Adams »

Hi Leigh

I've tried putting a 500ms delay in at the start and it still does not work.
I've set the timeout to 250 and it still does not work.

I'm trying to figure out how to do the ReceiveSR232Char. The help and the example on the net are not very clear.
Do I need to read each character individualy and then reassemble it into a string. When I read ReceiveRS232Char, I assume the 'int' value is the characters ASCII value. Is this correct? In which case I use a loop to read the value, convert to a character and then add to a string until the string is complete.

As the ReceiveRS232String has a maximum value of 6 then this would explain why it only reads the first 6 bits of the string ( H xxxx), but why is this only the case on the Advanced Module, while it reads all the string on the Serial module?

Regards Dave

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Serial inputs on Advanced Module

Post by LeighM »

Hi Dave
The receive string should have received all characters, but it does it internally in 6 character chunks, so the fact that you only get 6 implies a problem with the timeout. Sorry looks like I did not explain too well.
See attached example for using ReceiveRS232Char
Regards,
Leigh

ps. Another thing that is always worth doing is to flash the LED on the module with the LED_Control macro – just to ensure that the module is securely connected to power and CAN bus.
Attachments
RS232_String.png
(19.39 KiB) Downloaded 5372 times

Dave @Harper Adams
Posts: 33
Joined: Tue May 21, 2013 4:21 pm
Been thanked: 1 time
Contact:

Re: Serial inputs on Advanced Module

Post by Dave @Harper Adams »

Hi Leigh - Thanks for the reply

I'm trying to understand what the example does.
Basically does it check if the character of the serial data is CR or timeout inwhich case it jumps out of the loop. If not then it goes round the loop reading the next chracter each time.
Does it store the character in a buffer or add the character to the string RxCO2St?
I assume RXCO2St is a string variable with a lenght of [StrLength].
I've tried to create such a variable, but flowcode doesn't let me. It say the variable has to be <32 character long and can't include spaces.
Is the variable Character an INT or a string?

Regards Dave

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Serial inputs on Advanced Module

Post by LeighM »

Hi Dave,

Yes your description is correct.
It is storing each character in the buffer at an incremental point, which is the same as adding the character to the string.
(It becomes a printable string when the null terminator is appended)

The sample code uses the variables as you already had them in your flowchart.
I also added a Byte Done
Int Character
Int StrLength
String RxC02St[34]
34 being the maximum string length
StrLength is the actual character count of the string received
The MIAC PrintString prints whatever is in the string RxC02St up to the null terminator character.

Regards
Leigh

Dave @Harper Adams
Posts: 33
Joined: Tue May 21, 2013 4:21 pm
Been thanked: 1 time
Contact:

Re: Serial inputs on Advanced Module

Post by Dave @Harper Adams »

Hi Leigh

I've got it to work and it works on both the Advanced and Serial Modules.
I've had to increase the timeout to 500 as sometimes it misses the beginning of the string.
It always puts a y (ASCII 152) in front of the string. Generally just one but sometimes two or more. If it puts in more than two then the end of the string is cut off (presumably because the string length exceeds 34). Do you know why it puts a y in front?
I've also added some extra code so that if it exceeds the timeout then it prints "timeout". (Decision box with 'if Character = 0x2f' followed by a print"timeout" on the yes branch). I've tested it by switching off the sensor. It works, but takes about 25 seconds to pick this up when I was expecting approximately 500ms. I tried changing the timeout value and it doesn't appear to make any difference in the time it takes to pick up that there is no signal.

Thanks for your help
Dave

Post Reply