Read from USB port using Visual C++ SerialPort object

I have a Texas Instruments eZ430-RF2500 USB dongle that I am trying to communicate with. I have successfully written bytes to a SerialPort object and they have arrived at the chip, but I haven't been able to read anything. I've tried using SerialPort1->ReadExisting(), but no luck. Can you give me any suggestions as to how people usually go about interfacing Windows applications to USB devices? I'm brand new to this.

Thanks a lot!

Reply to
Ishmael
Loading thread data ...

Aha! Another RF2500 user!

Ishmael,

The "MSP430 Application UART" behaves, in most respects, just like a serial port. It defaults to registering as COM4, but you can change that, if you haven't already run across it, via the "ez430-RF2500 Sensor Monitor" app under Menu->Settings/Port: (I was going to make a remark about the unoriginality of a menu labelled Menu, but I've had weeks like that, too ).

The first thing you should check is that the output bits are actually getting across the USB bus. You can monitor the F2274's UART output through the above- mentioned "ez430-RF2500 Sensor Monitor" app under Menu->Console.

If bits are getting _to_ the chip, but not being delivered _from_ it, I'd guess that the F2274 isn't set up properly. Probably not a clock problem, again because characters are getting assembled properly, but you might check your "crossbar" registers (PxSELx), especially P3SEL. I found this note in something I write a few months back:

// If you don't give the pins to the USART, all of the above // is wasted. P3SEL |= 0x30; // P3.4,5 = USCI_A0 TXD/RXD

After at least one occasion where the port came up as COM5 I wrote the attached C#/.NET program to find it and then sit and listen to the "debugging" output my MSP430 was writing through the F2274's hardware UART. Don't know if it will help in your particular situation, but at least it shows that you _can_ get characters out of the F2274 USART and back to (in my case) MSWinXP. (If you're not running MSVStudio2005, hopefully parts of the code or comments might help.)

Oh, and if you're not already aware of it, TI has set up an information exchange called E2E at:

TI E2E Community https: //community.ti.com/

Good luck!

Frank McKenney

--------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.IO; using System.IO.Ports; using System.Threading;

using System.Management; // Needs Project->Add .NET reference

namespace MSP430_UART_Monitor { class Program {

static void Main(string[] args) {

const string TI_UART_Description = "MSP430 Application UART"; string sComPortName = FindCOMPortFromDescription(TI_UART_Description);

// If UART not found (MSP dongle not plugged in), exit if (sComPortName == "") { Console.WriteLine("Press any key to continue"); while (Console.KeyAvailable == false) { } Environment.Exit(1); } Console.WriteLine("Opening {0} as {1}", TI_UART_Description, sComPortName); SerialPort p = new SerialPort(); p.PortName = sComPortName;

p.BaudRate = 9600; Console.WriteLine("Buad rate: {0}", p.BaudRate); p.Parity = Parity.None; p.DataBits = 8; p.StopBits = StopBits.One; p.ReadTimeout = 0; // Return immediately if no data //p.ReadBufferSize = 1024; //p.WriteBufferSize = 1024;

// "Dongle" appears to be plugged in, but Someone Else // (e.g. the TI Demp App) may be using it. if (OpenPort(ref p)) {

p.BaudRate = 9600;

string s; while (true) { s = p.ReadExisting(); Console.Write(s); //if ( s.Length > 0 ) // Console.WriteLine(HexString(s)); //p.Write(s); // No loopback!! } //p.Close(); } else { Console.WriteLine("Unable to open port {0}", p.PortName); Console.WriteLine("Press any key to continue"); while (Console.KeyAvailable == false) { } Environment.Exit(1); } }

static bool OpenPort(ref SerialPort p) {

bool success = false; // Attempt to open serial port try { p.Open(); success = true; } catch (Exception e) { Console.WriteLine("Error opening {0}: {1}", p.PortName, e.Message); Console.WriteLine("Press any key to continue"); while (Console.KeyAvailable == false) { } Environment.Exit(1); // success = false; } return (success); }

public static string FindCOMPortFromDescription( string DevMgrDescription) {

WqlObjectQuery wqlQuery = new WqlObjectQuery( "SELECT * from Win32_PnPEntity WHERE Description = '" + DevMgrDescription + "'"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(wqlQuery);

// One port == good. // Zero ports = bad. // More than one port: try first. ManagementObjectCollection usbserials = searcher.Get(); string s = ""; if (usbserials.Count == 0) { Console.WriteLine("COM port for {0} not found", DevMgrDescription); } else { // Now that we know that there is at least one port... if (usbserials.Count > 1) { Console.WriteLine("Multiple MSP Appliction UARTs" + " found. First will be used"); } foreach (ManagementObject mo in usbserials) { //Console.WriteLine(mo.ToString()); //Console.WriteLine("Property: {0}: {1}", // "Name", mo["Name"]); //Console.WriteLine("Property: {0}: {1}", // "Description", mo["Description"]); string sName = mo["Name"].ToString(); int p1 = sName.IndexOf("("); int p2 = sName.IndexOf(")", p1); s = sName.Substring(p1 + 1, (p2 - p1) - 1); break; // Keep COMx port from first only } } return (s); }

public static string HexString(string s) {

string xs = "";

for (int i = 0; i < s.Length; i++) { xs += String.Format("{0:X}", (int)s[i]); } return (xs); } } }

---------------------------------------------------------

-- I do not deny that laws are important, but...the passage of new laws has continually served as a substitute for thought. -- Aldo Leopold

-- Frank McKenney, McKenney Associates Richmond, Virginia / (804) 320-4887 Munged E-mail: frank uscore mckenney ayut mined spring dawt cahm (y'all)

Reply to
Frnak McKenney

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.