Solved

Serial port rs232 comunication bi-directional mode maby php and visual basic

Posted on 2011-02-27
9
1,949 Views
Last Modified: 2012-08-13
Hi, I need some Best ideas for a project that I am building,

I need create a standart way software solution to comunicate with many medicaL instruments,
like : ADVIA,CELL DYN, COBAS, PENTRA, CENTAUR, etc,
each instruments have their own standart data code comunication,
like :ABX,ASTM,H7,CVS,ARGOS,etc

the protocol comunication to all instruments is the same:
RS232 NULL MODEM db9 or db25 PINOUT, I have not ptoblems with the phical layer.

how this work:
intrument ask to pc for a worklist, pc send worklist data
when the instrument has finished all worklist task send the results back to pc.

the solutions that I am thinking is:

1.- Develop all in php, but can php listen in com1 in windows enviroment?
2.- create an visual basic script, for manage the serial comunication data as a proxy, and find the best way to integrate this application to php( that php processe requested data, making conection to database.
in this case is an hibrid solution

0
Comment
Question by:cyberlab
  • 5
  • 2
9 Comments
 
LVL 57

Expert Comment

by:giltjr
ID: 34993909
http://php.net/manual/en/function.fopen.php

seach for com1 and you will see some code that shows you how to write to COM1.  This may help you get started.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 34995148
I have written many apps using RS232 back in the old days way back in 76. Under Windows the problem with RS232 was a physical limit to the devices that you could connect to. But using USB and some kind of driver this limit may have been overcome.

What type of physical connection system are you going to use? Does it have any limits?
0
 

Author Comment

by:cyberlab
ID: 34996485
the application will be installed for manage one unique serial port this ou focos for simplicity.
that for each serial port we need only clone the aplication and install, normally each pc have 3 instruments not more, but not have limitation.

0
 

Author Comment

by:cyberlab
ID: 34996501
giltjr:

yes I  have starter dear, before post here, the question is more conceptual, that what is more better solution, stable,etc.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 17

Accepted Solution

by:
inthedark earned 500 total points
ID: 35055253
The objective are:

* to control lots of devices simply
* to be able to update the software for all devices in one simple hit; even if the systems are all currently running.

I have had a chance to think about a really good solution. In summary I would write a server application that starts up on a PC or server somewhere on the same LAN the server waits for devices to start up and register themselves to the server.

The Devices control software starts up and reads a control file that defines the device type, location, communication settings and communication mode.  The Server knows which clients are attached and how to talk to each device.  The Server sends commands to each client and the client echos the serial data back to the server. So the server is talking to each device sening RS232 commands via TCPIP which are received by the device control clients which then repeat the commands to the devices via RS232 and echo the RS232 responses back to the server via TCPIP.


You are going to need 3 EXE files; 2 clients exe and one server app.

--------------Exe 1 DevControl.EXE----------------------

Device control starter, lets give this a name like DevControl.exe

The DevControl.exe  will start and read a control file in the same folder DevControl.txt.  The DevControl.txt will contain the name of the latest version of the device control client. For example the DevControl.txt will look something like this:

DevControlV33.exe

For each device attached to the PC there will be a link in the start menu-programs-startup so it will start automatically when the pc is rebooted. The link will look something like this:

\\ServerName\DevData\DevControl.exe DeviceXYZ.txt

Devcontrol will start to run and then simple read the devcontrol.txt file find out what the latest exe version name is set it running passing the start parameters.

Dim sLatest As String

sLatest =ReadFile( App.Path & "\DevControl.txt")

Dim lPID as long

lPID = Shell(sLatest, vbNormalWindow)

End

Because this is a very simple program it would take only about  15 minutes to complete.

---------------------Exe 2 - Device Controller

Each time the Device controller is changed it is given a new name like DevControlV10.exe, the next version will be DevControlV11.exe, then DevControlV12.exe etc.  In this way the device control softwatre can be updated even while the systems are in operations. And also throughout the entire organisation there will only be one current exe making support and upgrade simple.


When the DevControlVxx starts running it reads the parameter file passed to it in the command line.

The parameter file could look like this:


Server=DEVSERVER
ServerPort=12345
Location=ICUBay1
DeviceType=PULSEMONITORXYX
ComSettings=COM3,8,N,1
DeviceProtocol=STANDARD_RS232


The device controller reads the control file to see which device it has attached.  It connects connects to the Server using the name and port specified. When the connection is established the device controller registers itself with the server it will send a message like.

Server.SendMessage "LOCATION=" + sDeviceLocation ;"DEVICETYPE=" + sDeviceType
 
The client then waits for a message from the server like "OK;ESCAPE=$%^;"

The client would store the escape sequence as this would be used in future control messages.

Further control messages start and end with the escape sequence that the server proposed. This is to simplefy the code that gets fired when a message from the server arrives. Normally data from the server will be echoed to the device. But if a message starts with an escape sequence it signifies that the message is a control message directed to the client rather than the device.  In this way the server can send control statements to the device control software. Allowing commands like EnterDebugMode (the device controller displays a monitor screen showing data send between server and the device) or Restart (telling the device controller to End and run the DeviceControl.exe so the latest version can be reloaded without or even commands like Reboot system could be actioned.

This program is just 3 small sections.

Startup Phase
  Read Device Control Ini information file.
  Connect to server

Wait for Server Commands
   Decode incoming server commands; look for escape sequence, if found action the command.
   
When the server sends the "Open Device" escape sequence the RS232 communication to the device is initiated.

Wait for RS232 activity, echo activity back to the server.

The code for this exe would be very simple to create and would only take about 2 to 4 hours to complete.

-------------------------Exe 3 DevServer.exe

This is the major part of the system would need the most thought but still quite simple.

Server Listens for new incoming TCP/IP connections.

New connections arrives, server receives location and device type and it stores the connection in a collection of connected clients and tells the client to Open the device and start data echo. All subsequent data form the client will be data echoed from the RS232 port.

Incoming data from a client, the server knows what type of device is connected to the client so it would decode the data according to the device type.

You could just simply hard code the handler for each device type in the main exe but a really cool way you be to create a with events object to handle the device type activity.  In this way you could add new objects to the server without having to recompile it.  Each handler object would have standard methods & properties and generate standard events. So when a new device connects to the server you would create a new instance of a client class.  The client class would contain the device type, the incoming socket,  a new instance of the object handler for device and other information like time of last activity, etc.

The key thing would be the device hander based on the device type sent from the client, so the class would look a bit like this:

Class DeviceClient()

Public WithEvents Sock As Winsock
Public DeviceType As String
Public DeviceLocation As String
Public LastMessage As Date
Public DeviceHandler As Object
Public Status As Long
End Class


So when the new connection arrives the TCPIP servers receives a connection request event where the server creates a new instance of a device client class and accepts the connection into the socket defined in the DeviceClient class. The server then adds the DeviceClient to a collection of Clients.

As soon as the server receives a new connection it would send the client a message so the client knows that it connected ok. Perhaps the server could send a message like "OK;" + sEscapeCode+";"

The client would send the server the locations and device type. The server would then create a handler object for the client and set the status of the DeviceClient to 1 to indicate client is connected and registered and the object is ready to process echo data.

Again this code would be quite easy to create and should only take a small number of hours.

------------------------------------Handler Classes

For each of your device types you would need to create a handler class with some methods and events.

Class SampleHandler()

Public Sub DataFromDevice(psMessage As String)

' Process in coming data
' you would need to decode the data and then raise events to feed the conclusion to the server so the server can display on a monitor

End Sub

The handler would depend on the messages that the device input protocol and the device output protocol.

Hope this helps, let me know if you would like any code samples :~}

One final comment; it would be better to make the server .Net or a language that can handle multiple threads.



 










 









 







0
 

Author Comment

by:cyberlab
ID: 35056435
nice model, this is very pointting in the rigth way, in this midle time, I have aready made same decision:

-Clients will have an small exe, acting as a port gateway serial/tcp in bi-directional mode, listen for connection started from any side. I have writed 90%

-Server willbe an php socket server runing in linux as a backgound process. 10% only for test.
and here we are posting this asks for this:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26868024.html


-At server side we are searching a create a standard way for normatize all direntes fiels coming from all devices, if you wan I have opened another post about this here:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26868015.html

in general, what is the best for manage rs232 basic data comunication?
in the small exe, (like ACK ENQ commands response interacting for data transmition) or at the tcp server we do all control data as the ACK ENQ and all data adquisition/tramsmition.



regards
0
 

Author Comment

by:cyberlab
ID: 35367274
inthedark have partially helped in the solution
0
 

Author Closing Comment

by:cyberlab
ID: 35367291
B: The Expert(s) provided an acceptable solution, or a link to an acceptable solution. May assign if you needed a bit more information to complete the task.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now