Redlion Raw Serial Port

MATT116

Member
Join Date
Dec 2009
Location
Dallas, TX
Posts
330
Working on a project where I need to set the voltage, current and read the status on some power supply's.
There are 5 power supply's.
Each has a address switch (0-7).
Power supply's are connected to each other through a RS-485 port.
I will be using the RS-232 port on the redlion (G07) to talk to the 1st power supply (1st power supply has a RS-232 port and a RS-485 port).
Power supply's use UART protocol.
I have communication and can read and write parameters.
I use the "ADDS" to talk to a specific power supply (0-7)
What I don't understand is why I have to break it down into two programs?
For example on a push buttons action:
On pressed: I set the address using: PortPrint (Port, "ADDS 3" + "\R\N");
On Release: I set the voltage using: PortPrint (Port, "SV" + DecToText(PWS1.VoltageSP,0,3,2,0,0) + "\R\N");
That works and I'm able to set the voltage however if I combine both of those commands into one program and trigger it with "on tick" or "on release" of a push button it doesn't work.
I don't understand what the difference is?
O-yea this is my first time writing a driver...
Thanks
 
I have not used the raw serial port myself but some ideas:
1) Timing. All together, it happens too fast for the slaves to handle. It might be that after the first PortPrint instruction, the slave responds, but if you run another instruction too quickly, the response gets mishandled or the slave isn't ready to receive again.

2) Invisible character. When you combine the logic into one program, are you using two PortPrint instructions? There may be a termination character that gets sent at the end of the instruction that is missing in between the instructions...

I am not sure if there is an easy way to add a delay inside a program, but you might be able to use a PortRead instruction with a short delay period to provide some time between the two PortPrint()s.
 
I have not used the raw serial port myself but some ideas:
1) Timing. All together, it happens too fast for the slaves to handle. It might be that after the first PortPrint instruction, the slave responds, but if you run another instruction too quickly, the response gets mishandled or the slave isn't ready to receive again.

2) Invisible character. When you combine the logic into one program, are you using two PortPrint instructions? There may be a termination character that gets sent at the end of the instruction that is missing in between the instructions...

I am not sure if there is an easy way to add a delay inside a program, but you might be able to use a PortRead instruction with a short delay period to provide some time between the two PortPrint()s.

1) Timing, happening to was fast was my first thought but I can use a switch statement and poll & read 6 parameters from the 1st power supply without issue running the program “on tick”.

2) yes I’m using two separate PortPrint instructions.

I’ll look at adding a portread after I set the address to delay and empty the port.
 
Last edited:
Use the Sleep() function to add a delay in a program.

I have not used the raw serial port myself but some ideas:
1) Timing. All together, it happens too fast for the slaves to handle. It might be that after the first PortPrint instruction, the slave responds, but if you run another instruction too quickly, the response gets mishandled or the slave isn't ready to receive again.

2) Invisible character. When you combine the logic into one program, are you using two PortPrint instructions? There may be a termination character that gets sent at the end of the instruction that is missing in between the instructions...

I am not sure if there is an easy way to add a delay inside a program, but you might be able to use a PortRead instruction with a short delay period to provide some time between the two PortPrint()s.
 
I'd be willing to bet that the issue is insufficient time between the PortPrint commands, as OkiePC suggested. I'd put both statements in a single program with a Sleep() command in between. You might want to assign the program to a background task, otherwise depending on the duration of the sleep it may cause the unit to appear to "lock up" for a moment.

Many serial devices will send back a response code to indicate that a command has been processed. It is considered good practice to receive that response and use it as a trigger to send the next command (rather than a fixed time delay), however this of course requires more programming and overhead.
 
Ok I was able to get everything working in a single program with a "switch"
First I set the address to the first power supply then do the 6 need query's. Then set the address to next power supply, then do the 6 need query's and so on through all the power supply's. This code only runs when there is no "Need to write".
The key was to set the address once then query not set the address before every query and also clearing the port before each query.

switch(State) {
// Query the 1st power supply
case 0:
PortPrint (Port, "ADDS 0" + "\R\N");
break;
// Request Status 0 (Alarms)
case 1:
ClearRx(Port);
PortPrint (Port, "STUS 0" + "\R\N");
Temp = PortInput(Port,0,13,400,6);
PWS1.Status0 = TextToInt(Temp,16);
break;
// Request Status 1
case 2:
ClearRx(Port);
PortPrint (Port, "STUS 1" + "\R\N");
Temp = PortInput(Port,0,13,400,6);
PWS1.Status1= TextToInt(Temp,16);
break;
// Request Actual Voltage
case 3:
ClearRx(Port);
PortPrint (Port, "RV?" + "\R\N");
PWS1.Voltage = PortInput(Port,0,13,400,6);
break;
// Request Actual Current
case 4:
ClearRx(Port);
PortPrint (Port, "RI?" + "\R\N");
PWS1.Amp = PortInput(Port,0,13,400,6);
break;
// Request Temperature
case 5:
ClearRx(Port);
PortPrint (Port, "RT?" + "\R\N");
PWS1.Temp = PortInput(Port,0,13,400,6);
break;
// Request Power Status
case 6:
ClearRx(Port);
PortPrint (Port, "POWER 2" + "\R\N");
Temp = PortInput(Port,0,13,400,6);
PWS1.Power = TextToInt(Temp,16);
break;

// Query the 2nd power supply
case 7:
PortPrint (Port, "ADDS 1" + "\R\N");
break;
 

Similar Topics

Good morning and new to the forum. Attempting to configure a RedLion CU30D using it's RS-232 port to log the input stream. "Raw" ASCII data is...
Replies
4
Views
1,602
Hello, I man trying to use a redlion DA10 converter to read data from a Bronkhorst mini cori flow meter over rs232. I cant seem to get the...
Replies
7
Views
1,528
Some questions on raw port usage on a Redlion G3, specifically UDP. I am trying to read arbitrary bytes from a UDP stream with Ethernet but I...
Replies
4
Views
4,402
Hi, I have a complex database in Crimson 3.0 and in one of the display pages I am trying to get a tag to show the sum of several other tags. The...
Replies
3
Views
134
Hi All, Hoping to get some insight into best way to terminate shielded twisted pair + common into a RJ45 required for RedLion RS485...
Replies
3
Views
186
Back
Top Bottom