1. Tracy Lamb
  2. PowerBuilder
  3. Wednesday, 11 September 2024 15:09 PM UTC

Anyone had any luck communicating with serial port devices in PB2022?  I asked a similar question a while back, and Chris offered a solution.  I tried implementing that code in my pop-up window, command button cb_read:

integer li_FileNum, li_rc
string ls_zygo_reading

li_FileNum = FileOpen ( "COM2:", LineMode!, Read!, LockRead!)
li_rc = FileRead(li_FileNum, ls_zygo_reading)
if li_rc <1 then
	MessageBox("FileRead Error", li_rc)
else
	st_zygo.text = ls_zygo_reading
end if
FileClose(li_FileNum)

The user takes the reading from the instrument first, then clicks cb_read, so something should be available to read.  FileRead always returns -1.

In old code I had a user event, ue_commnotify(unsignedlong device, longptr status) so I put the same event in my new pop-up window.  In my old code, I had a user object, uo_serial_port that did all of the processing, but I'm not testing that.  Just testing the FileRead operation.

MessageBox("ue_commnotify","Event triggered")
return 0

ue_commnotify is never triggered, and cb_read always returns -1 when I try to do a FileRead.  

I tried putting the ue_commnotify event in the main window, customer says they don't get a response when they take a measurement, meaning the event is never triggered.  If it was triggered, they would get a message. FileRead always returns -1.

Any advice or ideas on what to try next? Does anyone have a serial port object compatible with PB2022?

~~~Tracy

 

 

Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 12 September 2024 14:03 PM UTC
  2. PowerBuilder
  3. # 1

Have the user click the button before taking the reading.

Comment
  1. Tracy Lamb
  2. Thursday, 12 September 2024 23:26 PM UTC
That didn't work.

  1. Helpful
There are no comments made yet.
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Wednesday, 11 September 2024 16:13 PM UTC
  2. PowerBuilder
  3. # 2

Hi Tracy

I'm no expert, but I think you need to be ready to catch the data send through the com port. A file Read afterwards will be too late. We have a very old piece of PB code that receives data from the Com port but that is using some iffy 3rd party tool to listen to the port and that then writes the data to a text file as it arrives. The PB app sees the file and reads it etc....

From what you have said your previous solution had a custom event that was triggered when data was sent. I think that is the right route to take. The question is why is the event not being triggered now?

 

Regards

David

 

Comment
  1. Tracy Lamb
  2. Wednesday, 11 September 2024 19:42 PM UTC
Exactly... I tried putting the event in both the pop-up window and the main window to no avail.
  1. Helpful
There are no comments made yet.
Gregory Rusak Accepted Answer Pending Moderation
  1. Wednesday, 11 September 2024 16:10 PM UTC
  2. PowerBuilder
  3. # 3

Have you tried as a blob for the 2nd parameter to the FileRead() function, then decode it?

Comment
  1. Tracy Lamb
  2. Thursday, 12 September 2024 23:32 PM UTC
Haven't tried this. The file was in LineMode. The instrument I'm communicating with sends a complete message.... 7 or 8 bytes (not sure).
  1. Helpful
  1. Tracy Lamb
  2. Thursday, 12 September 2024 23:32 PM UTC
FileOpen
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 11 September 2024 15:23 PM UTC
  2. PowerBuilder
  3. # 4

Hi Tracy;

  Suggestion: Place your code in a TRY..CATCH block. The "exception" object should contain more information as the the File handling issue / error(s) encountered. Hopefully, that might shed some light into the COM Port issue.  HTH

Regards .. Chris

Comment
  1. Tracy Lamb
  2. Thursday, 12 September 2024 23:28 PM UTC
Not sure how much more information the exception object would have... the error code -1 comes from PB. Would the exception object have more information?
  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 12 September 2024 23:56 PM UTC
Only one way to find out. ;-)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.