You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 30th, 2017, 06:30 PM   #1
MATT116
Member
United States

MATT116 is offline
 
Join Date: Dec 2009
Location: Dallas, TX
Posts: 330
Redlion Raw Serial Port

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
  Reply With Quote
Old November 30th, 2017, 07:45 PM   #2
OkiePC
Lifetime Supporting Member
United States

OkiePC is offline
 
OkiePC's Avatar
 
Join Date: Mar 2005
Location: ENE of Nowhere Oklahoma
Posts: 9,983
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.
__________________
It's not all the variables I am most concerned with, it's the undiscovered constants.
  Reply With Quote
Old November 30th, 2017, 07:58 PM   #3
MATT116
Member
United States

MATT116 is offline
 
Join Date: Dec 2009
Location: Dallas, TX
Posts: 330
Quote:
Originally Posted by OkiePC View Post
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 by MATT116; November 30th, 2017 at 08:17 PM.
  Reply With Quote
Old December 4th, 2017, 10:42 AM   #4
BenDruck
Member
United States

BenDruck is offline
 
Join Date: Oct 2015
Location: US
Posts: 10
Use the Sleep() function to add a delay in a program.

Quote:
Originally Posted by OkiePC View Post
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.
  Reply With Quote
Old December 4th, 2017, 01:33 PM   #5
kolyur
Lifetime Supporting Member + Moderator
United States

kolyur is offline
 
kolyur's Avatar
 
Join Date: Oct 2004
Location: Wooster, Ohio
Posts: 1,409
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.
__________________
John
  Reply With Quote
Old December 5th, 2017, 12:30 PM   #6
arlenjacobs
Lifetime Supporting Member
Canada

arlenjacobs is offline
 
Join Date: Sep 2014
Location: Kelowna
Posts: 631
If using serial ports, especially custom code, I use a serial port analyzer.
You gotta get one of these:
Attached Images
File Type: jpg HPprotocol.jpg (38.5 KB, 30 views)
  Reply With Quote
Old December 5th, 2017, 12:31 PM   #7
arlenjacobs
Lifetime Supporting Member
Canada

arlenjacobs is offline
 
Join Date: Sep 2014
Location: Kelowna
Posts: 631
Just kidding. A couple USB to Serial port cables and this
http://www.serial-port-monitor.com/

I don't remember if the free version is enough, but the paid one is certainly worth the price.
  Reply With Quote
Old December 5th, 2017, 12:38 PM   #8
MATT116
Member
United States

MATT116 is offline
 
Join Date: Dec 2009
Location: Dallas, TX
Posts: 330
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;
  Reply With Quote
Old December 5th, 2017, 05:54 PM   #9
MATT116
Member
United States

MATT116 is offline
 
Join Date: Dec 2009
Location: Dallas, TX
Posts: 330
Quote:
Originally Posted by arlenjacobs View Post
Just kidding. A couple USB to Serial port cables and this
http://www.serial-port-monitor.com/

I don't remember if the free version is enough, but the paid one is certainly worth the price.
I used this software http://www.232analyzer.com/
with this cable setup. Worked perfectly.
Attached Images
File Type: png en_db9_monitor.png (1.9 KB, 22 views)
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Red Lion DSPSX Raw Serial Port amitpanvekar LIVE PLC Questions And Answers 35 September 2nd, 2016 08:23 AM
1756 enbt Prayder LIVE PLC Questions And Answers 35 May 11th, 2016 04:28 PM
PV600 comm problem RickParrot LIVE PLC Questions And Answers 28 January 23rd, 2016 06:02 AM
SLC 5/05 Communication Problem with Serial Port.. pranav.mistry003 LIVE PLC Questions And Answers 2 August 23rd, 2012 03:41 PM
Ethernet or Serial port AGENTTINFOIL LIVE PLC Questions And Answers 6 January 22nd, 2007 10:22 PM


All times are GMT -5. The time now is 12:55 PM.


.