Control ARM Ports through UART (String (Data Type) based commands)

An area to discuss ARM specific problems and examples

Moderator: Benj

Post Reply
karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Control ARM Ports through UART (String (Data Type) based commands)

Post by karthickefy »

Hi,
I'm new to Flowcode7. Currently I'm developing I/O controller using STM32F407VE ARM with USB serial/UART communication. I plan to control this ARM's IO's through LabVIEW via either USB (HID/Serial) or UART. I would like to send the command (USB/UART) to ARM to activate the port and my command is in String format (ex: "CH1-0" or "CH1-1" (0-Low/1-High)). I try to control the Switch block (in Flowcode7) with String and finally I realised that Switch block cannot support String(Data Type) and it supports only Integers (May be my understand is wrong. if wrong please correct me). I tried to convert String to integer but I were failed. Below is my requirement

Example: UART Command is in String data type.
CH1-1 = PORTA0 High
CH1-0 = PORTA0 Low
CH2-1 = PORTA1 High
CH2-0 = PORTA1 Low
CH1-1,CH2-1 = Both PORTA0 and PORTA1 High (control two ports parallel).

above listed Bold letter is the commands (send from LabVIEW to ARM through UART/USB)

Please guide me. Thanks for your help.

Karthick

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: Control ARM Ports through UART (String (Data Type) based commands)

Post by LeighM »

Hi Karthick,

There a several solutions to this.
The simplest is to just use one character per command. e.g.
A = PORTA0 High
B = PORTA0 Low
C = PORTA1 High
D = PORTA1 Low
E = Both PORTA0 and PORTA1 High (control two ports parallel).
etc.
Then the characters A,B etc can be recieved as single characters from the UART and tested directly in a switch.
This assumes that you have control over the protocol and don't need it to be human readable.
If you do, then you are going to need to do some string parsing, or do some string compares.
First you would need to read your strings from the UART, perhaps using CR/LF as a string terminator, such that you know when one command is complete.
Then test with

Code: Select all

if Compare$ (st,"CH1-1",0) = 0
Help with strings can be found here ...
http://www.matrixtsl.com/wikiv7/index.p ... omparisons

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Control ARM Ports through UART (String (Data Type) based commands)

Post by Benj »

Hi Karthick,

This page of our wiki will probably be useful for you. I've created a Labview controlled CNC machine using the techniques described.
http://www.matrixtsl.com/wikiv7/index.p ... ateMachine

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: Control ARM Ports through UART (String (Data Type) based commands)

Post by karthickefy »

LeighM wrote:Hi Karthick,

There a several solutions to this.
The simplest is to just use one character per command. e.g.
A = PORTA0 High
B = PORTA0 Low
C = PORTA1 High
D = PORTA1 Low
E = Both PORTA0 and PORTA1 High (control two ports parallel).
etc.
Then the characters A,B etc can be recieved as single characters from the UART and tested directly in a switch.
This assumes that you have control over the protocol and don't need it to be human readable.
If you do, then you are going to need to do some string parsing, or do some string compares.
First you would need to read your strings from the UART, perhaps using CR/LF as a string terminator, such that you know when one command is complete.
Then test with

Code: Select all

if Compare$ (st,"CH1-1",0) = 0
Help with strings can be found here ...
http://www.matrixtsl.com/wikiv7/index.p ... omparisons
Hi LeighM,
Thanks a lot. Based on your instruction I have tested with single character and String command to switch the port through RS232 and it is working fine. Attached are the code (Char and String) for your verification. But I cannot switch two sets of commands (ex: CH1-1,CH2-1) together. But 2 sets of Char (Ex: A,B) is working fine. Please guide me. Also please give some example for CR/LF as a string terminator on the end of commands.

Thanks.
Attachments
demo rs232 String.fcfx
(11.88 KiB) Downloaded 247 times
demo rs232 Char.fcfx
(11.38 KiB) Downloaded 247 times

karthickefy
Posts: 74
Joined: Thu Nov 30, 2017 3:21 am
Has thanked: 4 times
Been thanked: 9 times
Contact:

Re: Control ARM Ports through UART (String (Data Type) based commands)

Post by karthickefy »

Dear Leigh/Benj,
Please guide me for my above question. please give some example for CR/LF as a string terminator on the end of commands. Thanks

Karthick.

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: Control ARM Ports through UART (String (Data Type) based commands)

Post by LeighM »

Hi,
The ReceiveString is using the CF/LF as a string terminator, and returns the string that was read prior to the terminator.
You could do this yourself by calling ReceiveChar in a loop, on each character place them in a string buffer e.g. Sx[n] = ReceiveChar until CR is received.
I assume you want "CH1-1,CH2-1" to switch 1 and 2 on simultaneously, and sending CH1-1 then CH2-1 will not suffice?
One way to do that would be to check for the ',' after you have done the ReceiveString, e.g.
if Sx[5] = ',' then twin command has been received
You would need to clear it after testing, just in case a shorter string is received next time..

Code: Select all

Sx[5] = 0
You could use a similar method to test the command, e.g.

Code: Select all

channel_1 = Sx[2]
action_1 = Sx[4]
channel_2 = Sx[8]
action_2 = Sx[10]
Hope that helps

Post Reply