cancel
Showing results for 
Search instead for 
Did you mean: 

Reading/Writing to Com Ports

Former Member
0 Kudos
540

Are you able to read/write to Com Ports in PB using the standard File functions?  I have seen many posts saying you can do the following...


ll_Job = fileopen ("COM1:", StreamMode!, Write!, Shared!)

filewrite (ll_Job, char(27) + char(112) + char(80) + char(25) + char(250))

fileClose(ll_Job)

However, I have tried it and it won't let me open the port.  (For "ll_Job" is always set to -1).  Is there a best way to communicate with ports in PB?  We used to use an ActiveX control, but it doesn't work with 64 bit Windows.  Thanks.

I'm using PB 12.5.2 Build 5789 in Windows 7 64 bit.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi I use the code you can find attached.

I founded it many years ago into the net, nto tested with 64bit OS

Rename it in n_seriale.sru and then import in your library

Here an example to read:

n_seriale      inv_seriale

inv_seriale = create n_seriale

inv_seriale.init( 1 , "9600,N,8,1")  // 1 = COMPORT

inv_seriale.read(500,true)

if isvalid(inv_seriale) then

inv_seriale.done()

destroy inv_seriale

end if

Bye

Former Member
0 Kudos

Worked great, thanks.

Answers (1)

Answers (1)

Former Member
0 Kudos

You can use the MSCOMM32.ocx as an OLE object.

You need to register it first (REGSRV)