Sign in to follow this  
Followers 0
Eddy5

USB Comms?

8 posts in this topic

I'm trying to write a small app to read and log data from a weather station connected over USB (Oregon Scientific RMS300 which uses the WMR100 protocol).

Is there a way in AutoIt to read data packets from such a USB device?

Share this post


Link to post
Share on other sites



I'm trying to write a small app to read and log data from a weather station connected over USB (Oregon Scientific RMS300 which uses the WMR100 protocol).

Is there a way in AutoIt to read data packets from such a USB device?

AFAIK only if the usb driver simulates a serial port and surprisingly maybe, many pieces of equipment do just that. So unplug the device and look in Device Manager and see what Communication ports you have .(Probably Com1 and Com2.) Plug the device in and have another look at what com ports there are. If another one has appeared you are in luck, otherwise I am afraid I have no idea.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@Eddy5

This is the API's you need Read / Write USB devices

and this one More API's

So far the theory.

regards

ptrex

Wow, great link, thanks ptrex. When I read articles like that I just know I can take over the world. (I just need a liiiittle bit more time.)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks for the info guys. It's definitely a USB HID device so I'll have to get reading up on it.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I've found a DLL that sound do the trick

http://www.codeproject.com/KB/cs/USB_HID.aspx

and here

http://groups.google.com/group/usb_net/bro...a665ed504bfc697

The zip file contains the DLL and an EXE that is capable of reading the data from the weather station so I'm pretty sure this is the DLL to use.

Now I just need to work out how to use the DLL in AutoIt.

Here's some of the code (C I think) from the application

this.usb.ProductId = 51713;
            this.usb.VendorId = 4062;
            this.usb.Shared = usbShared;
            this.usb.OnSpecifiedDeviceRemoved += new System.EventHandler(this.usb_OnSpecifiedDeviceRemoved);
            this.usb.OnDeviceArrived += new System.EventHandler(this.usb_OnDeviceArrived);
            this.usb.OnDeviceRemoved += new System.EventHandler(this.usb_OnDeviceRemoved);
            this.usb.OnDataRecieved += new UsbLibrary.DataRecievedEventHandler(this.usb_OnDataRecieved);
            this.usb.OnSpecifiedDeviceArrived += new System.EventHandler(this.usb_OnSpecifiedDeviceArrived);
            this.usb.OnDataSend += new System.EventHandler(this.usb_OnDataSend);
            
            usbBuffer = new byte[256];
            workingBuffer = new byte[256];
            usbRecord = new byte[10][];
            for (int i = 0; i < usbRecord.Length; i++)
            {
                usbRecord[i] = new byte[i + 128];
            }

private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke(new DataRecievedEventHandler(usb_OnDataRecieved), new object[] { sender, args });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                string rec_data = "";
                foreach (byte myData in args.data)
                {
                    if (myData.ToString("x").Length == 1)
                    {
                        rec_data += "0";
                    }

                    rec_data += myData.ToString("x") + " ";
                }

                Array.Copy(args.data, 2, usbBuffer, myBufferPos, (int)args.data[1]);
                myBufferPos += (int)args.data[1];
                // to remove 1st byte
                this.lb_read.Items.Add(rec_data.Substring(3));
            }
        }
Edited by Eddy5

Share this post


Link to post
Share on other sites

I'm getting a bit stuck with this. Not really sure what I'm doing to be honest. If anyone has any advice on the AutoIt commands to get me going (i.e. how do I actually get AutoIt to get anything meaningful from the USBLibrary.dll or HID.dll) I'd be very grateful.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0