Send message by COM port

HouseBot Plugin Development Discussions.
DsA
Member
Posts: 7
Joined: Sun Nov 16, 2008 3:47 am

Re: Send message by COM port

Post by DsA »

I write own plug-in of the interface on C ++. Have downloaded at you SDK. In description SDK of a plug-in of the interface there is a description of functions HBHardwareInstanceInit () and HBHardwareInstanceTerminate (), but there is no description of function similar HBDeviceRun () (it is started in a new thread) which is in SDK a device plug-in. How to read the data from COM-port, in that case?
The second question. To send the data from a device plug-in to an interface plug-in it is possible by means of function pHB_SendInterfacePackToInterface (DEVICE_HANDLE hDevice, InterfaceArgumentPack* pPack). Whether there is an inverse function to send melon from an interface plug-in to a device plug-in.
menesi
Member
Posts: 51
Joined: Fri Jan 05, 2007 4:48 pm
Location: Debrecen, Hungary, EU

Re: Send message by COM port

Post by menesi »

I have practice with serial commhnication with HB's General Serial Module only, I have not yet that problem, which needs plugin development.
Try Scott to answer.
Laszlo Menesi
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Send message by COM port

Post by ScottBot »

I would strongly suggest deriving a class from the CHardwareInstance (for Hardware Interface plugins) and CDevice (for Device plugins) classes and structuring the code similar to the sample source code.

When HBHardwareInstanceInit() is called, you should initialize anything needed for your hardware interface plugin to run. This is where you would open the COM port and create any threads for ongoing tasks (like monitoring COM port reads) that you many need to perform. You have to return immediately from the HBHardwareInstanceInit(), so make sure that you create worker threads to do any background/ongoing work.

When the Device needs to send something to the hardware interface, it will call SendInterfacePackToInterface() (or pHB_SendInterfacePackToInterface if you are not using the CDevice base class). If the Device wants to receive notifications (like received data) back from the hardware interface, it must subscribe to a notification list by calling SubscribeToNotificationList(). You define the list name and filter that your hardware interface will use to communicate to your devices. When the Hardware Interface has information to send to Devices, it will call NotifySubscribedDevices() using the same list name and filter used by your devices.

Hope this answers your questions.
Scott
beginner
Member
Posts: 9
Joined: Wed Nov 05, 2008 1:32 pm

Re: Send message by COM port

Post by beginner »

Returning to the Generic Serial Plugin, I have another question. Usually sending commands to COM port, a 4-query:
1) IRP_MJ_CRATE
2) IRP_MJ_WRITE
3) IRP_MJ_CLEANUP
4) IRP_MJ_CLOSE

This can be verified using Portmon.

Tell me please, can I have in the Generic Serial Plugin IRP_MJ_CLEANUP?
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Send message by COM port

Post by ScottBot »

The generic serial hardware interface will open the connection to the port when the hardware interface is enabled. The IRP_MJ_CREATE gets sent then.

When changing Property Values and sending the Commands, it will cause the IRP_MJ_WRITE's to send the data.

It's not until you manually disable the hardware interface that the IRP_MJ_CLEANUP and IRP_MJ_CLOSE will get called.
Scott
beginner
Member
Posts: 9
Joined: Wed Nov 05, 2008 1:32 pm

Re: Send message by COM port

Post by beginner »

.jpg
.jpg (122.34 KiB) Viewed 8259 times

Maybe I need to set up something in the window? Also I would like to read more about each option.
menesi
Member
Posts: 51
Joined: Fri Jan 05, 2007 4:48 pm
Location: Debrecen, Hungary, EU

Re: Send message by COM port

Post by menesi »

There is a detailed description from this, titled as "Configuring the Generic Serial Plugin" in tutorials section of this portal.
Laszlo Menesi
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Send message by COM port

Post by ScottBot »

beginner wrote:...Also I would like to read more about each option.
The online help should provide the detail for all of the options.

And as menesi stated, there is a new tutorial for how to configure the generic serial plugins that you may find helpful.
Scott
Post Reply