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 March 4th, 2012, 11:52 AM   #1
Damaged
Lifetime Supporting Member
United States

Damaged is offline
 
Join Date: Oct 2008
Location: Alabama
Posts: 36
Red Lion and Serial Trigger for Microscan

Hello guys,

Red Lion - DSPGT000 using RS232 raw driver for port 1 and 2.

I am trying to send a serial trigger to 2 microscan barcode (1 on port 1 and the other on port 2) scanners without any luck. I can set up the scanner to use the external trigger and capture the string using the programs 1 and 2 below. But I would like to use the serial trigger. The microscan is setup to start a read using these settings:

Serial Trigger
Character (Delimited) - SP
Start Character (Non-Delimited) - 0x21 (!)
Stop Character (Non-Delimited) - 0x00 (NUL)

I have a flag bit from a plc when high triggers Program 4 (or a fifth program that will be used for port 2 if I can get port 1 working) then the second trigger for the same flag bit is set to 1 sec later that triggers Program 1 (or 2, depending on the flag/port).

When Program 4 is called, the micrsscan just sits dead. I can connect to the microscan and use the terminal with a "!" trigger and it works all day long.

If you see below in Program 4 I am using the "portprint (1, "!")" and I cant seem to understand why this is not working.

The next issue I have is using Program 3. After Program 1 and 2 have run and set flags (PORT1_COMPLETE = 1 that they have completed then Program 3 is called and always get the "PASS" string in tag COMPARE_STATUS. The compare program 3 is not as important as the serial trigger as I can do this in the PLC but I would like to find out what I am doing wrong.

I have also pasted (at the bottom) a command that TWControls posted early but didnt understand the structure.

Any help would be greatly appreciated. I can provide Project files if needed.

Program 1

cstring INPUT1 = PortInput (1, 0, 13, 500, 0);

if(INPUT1 != "")
PORT1_STRING = INPUT1;
INPUT1 = "";
PORT1_COMPLETE = 1;
PORT1_TRIGGER = 0;



Program 2

cstring INPUT2 = PortInput (2, 0, 13, 500, 0);

if(INPUT2 != "")
PORT2_STRING = INPUT2;
INPUT2 = "";
PORT2_COMPLETE = 1;
PORT2_TRIGGER = 0;


Program 3

COMPARE_STATUS = "";


if (PORT1_STRING == PORT2_STRING && PORT1_STRING == "NOREAD")
COMPARE_STATUS = "BC NO READ";

if (PORT1_STRING == "NOREAD" && COMPARE_STATUS == "")
COMPARE_STATUS = "BC1 NO READ";

if (PORT2_STRING == "NOREAD" && COMPARE_STATUS == "")
COMPARE_STATUS = "BC2 NO READ";

if (PORT1_STRING != PORT2_STRING && COMPARE_STATUS == "")
COMPARE_STATUS = "MISMATCH";

if (PORT1_STRING == PORT2_STRING && COMPARE_STATUS == "")
COMPARE_STATUS = "PASS";

if (COMPARE_STATUS != "")
START_COMPARE = 0;
PORT1_COMPLETE = 0;
PORT2_COMPLETE = 0;


Program 4

PortPrint(1, "!");






// declare locals
cstring line;
line = "!";
line += DecToText(PORT_WRITE_TAG, 0, 2, 1, 0, 0);
line += " to the serial port";

PortPrint(1, line);
__________________
  Reply With Quote
Old March 4th, 2012, 12:54 PM   #2
Clay B.
Lifetime Supporting Member
United States

Clay B. is offline
 
Clay B.'s Avatar
 
Join Date: Jun 2005
Location: Concord,NC
Posts: 1,304
I do something similar on some weight controllers. I do not have the code in front of me right now but What I do I Clear the buffer then send my command to my device. I then read back after this.

I have my port clear and write in one program and my read in another so I have separation.

The Clear function makes sure there is no data from a previous read. Doing a write directly after means the next thing to fill my buffer is what I want.

Sorry I cannot give you exact code but if you are still having issues Monday bump this thread and I will post what I do.
  Reply With Quote
Old March 4th, 2012, 12:57 PM   #3
Damaged
Lifetime Supporting Member
United States

Damaged is offline
 
Join Date: Oct 2008
Location: Alabama
Posts: 36
Clay B,

I was reading your thread on your scales trying to figure this out. So, is the PortPrint in program 4 correct? I will try the clear function as soon as I get a chance, had to move on to another project today.

thanks for you reply!
__________________
  Reply With Quote
Old March 4th, 2012, 03:44 PM   #4
Clay B.
Lifetime Supporting Member
United States

Clay B. is offline
 
Clay B.'s Avatar
 
Join Date: Jun 2005
Location: Concord,NC
Posts: 1,304
Quote:
Originally Posted by Damaged View Post
Clay B,

I was reading your thread on your scales trying to figure this out. So, is the PortPrint in program 4 correct? I will try the clear function as soon as I get a chance, had to move on to another project today.

thanks for you reply!
Yes it is correct if you want to send an ! to your device. In my case I send a P to get data .

While reading this I realized there is no actual clear buffer Command. These is however there is a way to read everything in the buffer just prior to sending the write command basically your transmit program will look something like this:

Quote:
// clear out Port 2 buffer by reading until there is nothing left. The trick is the
//while loop. The loop keeps running until a -1 is returned. The -1 means the
//buffer is empty. Since my wait time is zero I am not waiting on any data in
//transit.

while(PortRead(2, 0) != -1) {}

// send out command for data

PortPrint(2,"P");
Yes it looks bizarre, but it does work.

Now that you have sent your command you need to listen. I listen a certain way and that is below. Also even though I have these in separate programs, I call them with the same trigger. Because of the way subroutines work separating them guarantees things are done the way I want. I just call the transmit before the receive.

Quote:
cstring P2data;
//Read the data on Port 2. First character I am looking for is an Hex 20
// End character I am looking for is a Hex 4E (the 0x tells the program your
//using hex numbers) I want to wait for 1500 milliseconds to go from my first
//to last character and if I don't get there I close the port (keeps things from
//locking up but will slow things down so you know when you have a Comm
//problem). My length is zero because I want every character of the string
//coming back. I could tell it to end after a certain length but with the zero if
//I get noise I will just time out.

P2data := PortInput(2,0x20,0x4E,1500,0)
On your reads it is a good idea to know what you are expecting. It is real handy if you know what your leading character is. This way you yank out only the data you want without the wrappers. Because I know the beginning and ending characters I can slice and dice my incoming data even though the numbers will vary with the amount of weight on the scale and also I can switch back and forth between zero, one and two decimal places on my scales without headache.

Last edited by Clay B.; March 4th, 2012 at 03:47 PM.
  Reply With Quote
Old March 11th, 2012, 09:12 PM   #5
Damaged
Lifetime Supporting Member
United States

Damaged is offline
 
Join Date: Oct 2008
Location: Alabama
Posts: 36
Clay B

Finally got the Red Lion installed. Here was the problem.

I had 2 microscan scanners that I was using to test with. Once I had everything reading I downloaded the customers microscan file to the scanner I was working with. That is when I setup the serial trigger and it never worked, ......(tail tucked between legs) I never checked the port settings in the new file and they were different from what I had the G3 setup for.

So the "portprint" would have worked out of the box if I had the correct setting on each port. So Once I changed the port settings to match WHA LA....worked.

The only thing is that I could not get the compare program working.
__________________
  Reply With Quote
Old March 12th, 2012, 07:20 AM   #6
Clay B.
Lifetime Supporting Member
United States

Clay B. is offline
 
Clay B.'s Avatar
 
Join Date: Jun 2005
Location: Concord,NC
Posts: 1,304
Glad to here you got it talking. For me getting the Comms to work is where I spend most of my time on new systems.

As far as your Compare Program The reason you got "Pass" and nothing else is kind of obvious to me. Mainly because I do it all the time.

You have a NOREAD but I see no where that you put that into either of your Port1_String or Port2_String so that line will never work.

By that logic the next 2 lines will not work either.

The 4th line with the mismatch is a bit of a puzzle. Unless you fat fingered the "" and put a space in there either in the compare or at the beginning of the program it should work

The 5 line was set when you first fired the system up since everything equaled "".

Another bit of advice: When you run your read programs place something into PORT1_String and PORT2_STRING before you do the data compare to load the data from INPUT1 and INPUT2. That NOREAD string would work.
  Reply With Quote
Old March 14th, 2012, 08:13 PM   #7
Damaged
Lifetime Supporting Member
United States

Damaged is offline
 
Join Date: Oct 2008
Location: Alabama
Posts: 36
Clay B

The "NOREAD" is a string that will populate the tags by the barcode scanners on a no read (timeout).

The 4th line:

if (PORT1_STRING != PORT2_STRING && COMPARE_STATUS == "")
COMPARE_STATUS = "MISMATCH";

If barcode scanner string 1 is not equal to barcode scanner 2 AND compare status equals null (blank, nothing) then populate compare status with "MISMATCH".

Good point on line 5. How can I loop the first 4 compares 5 or 6 times then run the compare on line 5? hmmmmmm

The program is called after the port read so the port string tags should be populated by the time it runs.

Thanks for your replies Clay B!!!!
__________________
  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 G308 blown up during programming ggc LIVE PLC Questions And Answers 7 November 11th, 2011 02:03 PM
Connecting to Red Lion HMI through VSP Mark. LIVE PLC Questions And Answers 3 October 25th, 2011 08:29 AM
Logix5000 + Red Lion + serial cable mainstreetmark LIVE PLC Questions And Answers 1 May 13th, 2011 11:47 AM
Red Lion G3 Serial problem Clay B. LIVE PLC Questions And Answers 11 December 6th, 2010 03:08 PM
Red Lion G310 Modbus Comms pauly LIVE PLC Questions And Answers 2 December 21st, 2009 10:24 AM


All times are GMT -5. The time now is 04:44 AM.


.