News:

  • August 21, 2026, 04:21:36 PM

Login with username, password and session length

Author Topic: BRX -> Internal Serial -> read-only sensor  (Read 37545 times)

Zero Magnitude

  • Full Member
  • ***
  • Posts: 22
BRX -> Internal Serial -> read-only sensor
« on: March 22, 2018, 12:37:33 PM »
What's the bare minimum code to read data from a serial port? 

Edit for answer: STREAMIN is the only block required. 

Setting up the port and checking the hardware layer is best done outside the ladder logic.   

---

I've looked at the example IntSerial server port code, and it seems like complete overkill for what I want to do. 

The plan is to read from a Honeywell linear sensor that puts out data at "RS-232-type digital" at 57.6kbits/s (The SPS-L225-HDLS ).  That is the sum total of all information I have on the sensor's communication and setup.  The datasheets and specs don't tell me the part, bits, stop, etc.  ¯\_(ツ)_/¯

The sensor has a 6-24V input, ground, and output.  I've got 12V and ground hooked to the same PLC power, with additional ground pigtail to the IntSerial GND.  The output wire is attached to the IntSerial RX/D- pin.  Nothing is attached to the TX/D+ pin.   

BRX is a BX-DM1-19ED2-D

All I'm looking for is simple code that reads in the info from the sensor.  If I could get bad information, like if it's the wrong parity or whatever, I can use trial and error to find the right settings.  All I'm getting is errors though, either with the sample code or with a couple of rungs that I've been trying.  (SETUPSER, OPENDEV, DEVREAD, STREAMIN) and it feels like I'm just missing one step somewhere. 

I can't find anything in the online documentation, the forums here or at AD, and I'm stuck.  If there was even a way to read the error codes (instead of "Failure Detected") that would also be helpful.



« Last Edit: March 23, 2018, 01:37:56 PM by Zero Magnitude »

racrowd

  • Full Member
  • ***
  • Posts: 23
Re: BRX -> Internal Serial -> read-only sensor
« Reply #1 on: March 22, 2018, 01:33:55 PM »
I don't know if this is the correct way, but I always started rs232 projects with talking to a PC using a software like Putty or Hyperterminal.

Zero Magnitude

  • Full Member
  • ***
  • Posts: 22
Re: BRX -> Internal Serial -> read-only sensor
« Reply #2 on: March 22, 2018, 01:49:55 PM »
It's been a long time since I've had a computer with a serial port. 

I've got a USB / 232 cable on order but it's not here.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: BRX -> Internal Serial -> read-only sensor
« Reply #3 on: March 22, 2018, 02:07:33 PM »
Sad, sad, sad.  Went to the Honeywell site and could not find ANY details about THEIR product.  Tried google.  Nothing.  I'm guessing that they want to sell you a "comm card" to talk to it?

Sad, sad, sad.

Hopefully somebody out there has some information about Honeywell.  I think they are a big enough company that others have used their stuff?   ;)

Zero Magnitude

  • Full Member
  • ***
  • Posts: 22
Re: BRX -> Internal Serial -> read-only sensor
« Reply #4 on: March 22, 2018, 02:11:33 PM »
I'm still leaning towards "I have not got this coded correctly" vs. "Honeywell is to blame". ;)

I'm now getting "Attempted operation not supported by device in STREAMIN" which is weird, because isn't STREAMIN the only way to get data out of the RS-232 stream? 

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: BRX -> Internal Serial -> read-only sensor
« Reply #5 on: March 22, 2018, 02:19:24 PM »
You probably don't need the OPENDEV or DEVREAD.  Definitely get rid of the OPENDEV.  That's only useful if you need to dynamically change your serial ports at runtime (e.g. sometimes I want to use the IntSerial, sometimes SERIO port A, sometimes SERIO port C).

If you are going to use DEVWRITE, make sure you are waiting for it to finish (see the On Success bit) before you try to do a STREAMIN or STREAMOUT.

The serial port needs to be configured in the System Configuration as "Program Control" (aka ASCII, using STREAMIN/STREAMOUT).  Make sure that is written to the PLC.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: BRX -> Internal Serial -> read-only sensor
« Reply #6 on: March 22, 2018, 02:20:55 PM »
Also, don't forget to change your STREAMIN to use @IntSerial, NOT the Device Reference from your OPENDEV instruction, which is not needed.

Zero Magnitude

  • Full Member
  • ***
  • Posts: 22
Re: BRX -> Internal Serial -> read-only sensor
« Reply #7 on: March 22, 2018, 02:26:37 PM »
Thanks, that's definitely an improvement!

I'm now seeing the number of messages in the queue increasing in response to me wiggling on the sensor, but I'm not seeing the data come out.  Once IntSerial.InQueue gets to 1023, that sticks there until I power cycle the PLC. 

I'm trying both reading to a string and reading to a D location. 
« Last Edit: March 22, 2018, 02:29:54 PM by Zero Magnitude »

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: BRX -> Internal Serial -> read-only sensor
« Reply #8 on: March 22, 2018, 02:30:54 PM »
Post your STREAMIN rung.  Either a screen shot or copy/paste the mnemonics (select the STREAMIN rung using Shift+DownArrow key, then do Ctrl+C, then paste the clip as text here, removing all the SYSCONFIG section stuff)

Zero Magnitude

  • Full Member
  • ***
  • Posts: 22
Re: BRX -> Internal Serial -> read-only sensor
« Reply #9 on: March 22, 2018, 02:50:52 PM »
Do you mean this?

Code: [Select]
// Ver(103) PCU(3) Do-more Designer Clip   Source Project:  Format: Do-more Designer 2.00+  DO-MORE Ladder  PLC BX-DM1-18ED2-D


STRGT IntSerial.InQueue 0
AND C0
STREAMIN @IntSerial 2 0x0 100 0x0 SS0 DST511 DST511 DST511 0x0 0x0 C4 C5

C0 is the OPENDEV success flag.  It's programmed to open with a switch so I have time to pick up the sensor after hitting run.

I put the SETUPSER back so I could easily modify the settings without the warning.  I'm not really sure what the settings for the sensor are, so I'm running through the 12 cases.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: BRX -> Internal Serial -> read-only sensor
« Reply #10 on: March 22, 2018, 03:04:54 PM »
It appears that your device is probably just broadcasting characters, and you have filled up your serial port buffer.

You will be spinning your wheels if you just keep cycling through various parity/start/stop bits using SETUPSER before every STREAMIN.  Try to figure out what it actually is (pause between each one for 3 seconds).  Then set it up statically in the System Configuration.

Trust me, nail that down first before thinking you have a "logic" problem with your STREAMIN.  You may still have some STREAMIN issues, but until you nail down the physical layer, the code ain't gonna work.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: BRX -> Internal Serial -> read-only sensor
« Reply #11 on: March 22, 2018, 03:28:20 PM »
I don't know if this is the correct way, but I always started rs232 projects with talking to a PC using a software like Putty or Hyperterminal.

Yeah, what he said.  I remember some terminal programs (not sure which ones) will autobaud, which hopefully means they'll automagically detect the port settings as well.  N81 and 7E1 are both very commonly used configurations.  If you have to go by trial and error, I'd try those, and possibly O81 first.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Zero Magnitude

  • Full Member
  • ***
  • Posts: 22
Re: BRX -> Internal Serial -> read-only sensor
« Reply #12 on: March 22, 2018, 03:42:33 PM »
Okay, there's now one rung of code total, it's the STREAMIN block.  When I play with the sensor, the input buffer counter increases and the RX light goes on.  I guess it's 8/1/N?

How can I reset the buffer, and how can I get data (even bad data) out of the buffer?  SS0 doesn't change at all.     

Code: [Select]
// Ver(103) PCU(3) Do-more Designer Clip   Source Project:    Format: Do-more Designer 2.00+  DO-MORE Ladder  PLC BX-DM1-18ED2-D


STRGT IntSerial.InQueue 0
STREAMIN @IntSerial 1024 0x0 100 0x0 SS0 DST511 DST511 DST511 0x0 0x0 C4 C5

No computers here have a serial port.  I can not possibly connect the PLC to a serial port. 


« Last Edit: March 22, 2018, 04:06:08 PM by Zero Magnitude »

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: BRX -> Internal Serial -> read-only sensor
« Reply #13 on: March 22, 2018, 03:53:46 PM »
DEVCLEAR

Zero Magnitude

  • Full Member
  • ***
  • Posts: 22
Re: BRX -> Internal Serial -> read-only sensor
« Reply #14 on: March 22, 2018, 04:17:13 PM »
Ah, well now I have garbage coming in! 

It looks like if the buffer is zero, the PLC will read garbage but if if the buffer has anything in it it'll jam and not read anything until .inqueue gets reset, and then it'll read [some number] of garbage packets until it jams, then .inqueue will increase until it gets reset again.   

So are there things I have to code in to get the data to go from buffer to a string / D location that aren't part of the STREAMIN block?  Do I have to manually put in the DEVCLEAR box when it reads a packet?  Do I have to wait for a flag to be set before I read the stream?
« Last Edit: March 22, 2018, 04:48:24 PM by Zero Magnitude »