Jonathan
08-07-2006, 06:53 PM
I have CML driver code that finds and opens a USB HID device sucessfully and then dies when I try to write 8 bytes to it.
When calling m_USB.Write(m_IOBuf, 8, 2000) I get the following:
http://img391.imageshack.us/img391/6076/1hv9.jpg
Unfortunately, I've no idea what this means so understanding what is going wrong is difficult. Here is the work in progress code that is causing the above error:
Class=[NonFinal]
ClassPath MEng.User.CQC.Drivers.PowerLincUSB.DriverImpl;
ParentClass MEng.System.CQC.Runtime.CQCDriverBase;
EndClass;
Imports=
MEng.System.Runtime.MemBuf;
MEng.System.Runtime.USBHID;
MEng.System.CQC.Runtime.CQCFldDef;
#BeginDebug
MEng.System.Runtime.ConsoleOutStream;
#EndDebug
EndImports;
Literals=
Card2 kVendorId(0x10BF);
Card2 kProductId(0x0004);
// All IBIOS commands are prefixed with STX followed by the command number
Card1 kCmd_STX(0x02);
// 0x80 in the count field indicates the device is ready to receive more data
Card1 kCmd_Ready(0x80);
// IBIOS Commands
Card1 kCmd_Download(0x40);
Card1 kCmd_FixedLengthMessage(0x41);
Card1 kCmd_Upload(0x42);
Card1 kCmd_VariableLengthMessage(0x43);
Card1 kCmd_GetChecksum(0x44);
Card1 kCmd_EventReport(0x45);
Card1 kCmd_Mask(0x46);
Card1 kCmd_SimulatedEvent(0x47);
Card1 kCmd_GetVersion(0x48);
Card1 kCmd_DebugReport(0x49);
Card1 kCmd_X10ByteReceived(0x4A);
Card1 kCmd_InsteonMessageReceived(0x4F);
EndLiterals;
Members=
USBHID m_USB;
MemBuf m_IOBuf;
String m_Path;
Time m_Time;
#BeginDebug
ConsoleOutStream m_Con;
#EndDebug
EndMembers;
//
// Constructor and an entry point for testing purposes
//
Methods=[Public,Final]
Constructor() : m_IOBuf(8, 8);
Begin
EndConstructor;
Method Start() Returns Int4
Begin
Simulate();
Return 0;
EndMethod;
EndMethods;
//
// Helper methods for reading, writing, and parsing messages
//
Methods=[Private,Final]
Method InitIoBuffer([In] Card1 Byte1,
[In] Card1 Byte2,
[In] Card1 Byte3,
[In] Card1 Byte4,
[In] Card1 Byte5,
[In] Card1 Byte6,
[In] Card1 Byte7,
[In] Card1 Byte8)
Begin
m_IOBuf.SetAll(0);
m_IOBuf.PutCard1At(0, Byte1);
m_IOBuf.PutCard1At(1, Byte2);
m_IOBuf.PutCard1At(2, Byte3);
m_IOBuf.PutCard1At(3, Byte4);
m_IOBuf.PutCard1At(4, Byte5);
m_IOBuf.PutCard1At(5, Byte6);
m_IOBuf.PutCard1At(6, Byte7);
m_IOBuf.PutCard1At(7, Byte8);
EndMethod;
Method WriteIoBuffer()
Begin
#BeginDebug
m_Con.FmtStr("S:");
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(0), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(1), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(2), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(3), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(4), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(5), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(6), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(7), Radices.Hex);
m_Con.NewLn();
m_Con.Flush();
#EndDebug
m_USB.Write(m_IOBuf, 8, 2000);
EndMethod;
Method ReadIoBuffer() Returns Boolean
Begin
If (m_USB.Read(m_IOBuf, 8, 100, False))
#BeginDebug
m_Con.FmtStr("R: ");
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(0), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(1), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(2), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(3), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(4), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(5), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(6), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(7), Radices.Hex);
m_Con.NewLn();
m_Con.Flush();
#EndDebug
Return True;
EndIf;
Return False;
EndMethod;
Method CheckStatus() Returns Boolean
Begin
InitIoBuffer(2, kCmd_STX, kCmd_GetVersion, 0, 0, 0, 0, 0);
WriteIoBuffer();
Return False;
EndMethod;
EndMethods;
//
// Overrides of required methods defined by our base class. We must implement
// these or the compiler will complain. These are how the underlying driver
// infrastructure calls us to let us know events have occured.
//
Methods=[Public,Overrides,Final]
//
// This is called when we are first loaded. It is just for us to do any
// data initialization, to register our fields, set our poll times, and
// so forth. Here we are checking to see if the PowerLinc is present in
// the system.
Method InitializeOther([In] MEng.String CfgString, [In] MEng.System.Runtime.NamedValMap PromptVals) Returns DrvInitRes
Begin
If (!m_USB.FindDevice(kVendorId, kProductId, m_Path))
If (GetVerboseLevel() >= VerboseLvls.Medium)
LogMsg("The Insteon PowerLinc Controller is not present");
EndIf;
#BeginDebug
m_Con.FmtStr("The Insteon PowerLinc Controller is not present\n");
m_Con.Flush();
#EndDebug
Return DrvInitRes.Failed;
EndIf;
#BeginDebug
m_Con.FmtStr("Insteon PowerLinc Controller found.\nPath=");
m_Con.FmtStr(m_Path);
m_Con.NewLn();
m_Con.Flush();
#EndDebug
Return DrvInitRes.WaitCommRes;
EndMethod;
Method GetCommResource() Returns Boolean
Begin
Try
m_USB.Open(kVendorId, kProductId);
EndTry;
Catch
If (GetVerboseLevel() >= VerboseLvls.Medium)
LogMsg($Exception.GetErrorText());
EndIf;
#BeginDebug
m_Con.FmtStr("Failed to open USB port\n");
m_Con.Flush();
#EndDebug
Return False;
EndCatch;
#BeginDebug
m_Con.FmtStr("Opened USB port\n");
m_Con.Flush();
#EndDebug
Return True;
EndMethod;
Method Connect() Returns CommResults
Begin
CheckStatus();
Return CommResults.Success;
EndMethod;
Method Poll() Returns CommResults
Begin
Return CommResults.Success;
EndMethod;
Method CardFldChanged([In] Card4 FldId, [In] Card4 ValWritten) Returns CommResults
Begin
Return CommResults.Success;
EndMethod;
Method FreeCommResource() Returns Boolean
Begin
m_USB.Close();
Return True;
EndMethod;
EndMethods;
When calling m_USB.Write(m_IOBuf, 8, 2000) I get the following:
http://img391.imageshack.us/img391/6076/1hv9.jpg
Unfortunately, I've no idea what this means so understanding what is going wrong is difficult. Here is the work in progress code that is causing the above error:
Class=[NonFinal]
ClassPath MEng.User.CQC.Drivers.PowerLincUSB.DriverImpl;
ParentClass MEng.System.CQC.Runtime.CQCDriverBase;
EndClass;
Imports=
MEng.System.Runtime.MemBuf;
MEng.System.Runtime.USBHID;
MEng.System.CQC.Runtime.CQCFldDef;
#BeginDebug
MEng.System.Runtime.ConsoleOutStream;
#EndDebug
EndImports;
Literals=
Card2 kVendorId(0x10BF);
Card2 kProductId(0x0004);
// All IBIOS commands are prefixed with STX followed by the command number
Card1 kCmd_STX(0x02);
// 0x80 in the count field indicates the device is ready to receive more data
Card1 kCmd_Ready(0x80);
// IBIOS Commands
Card1 kCmd_Download(0x40);
Card1 kCmd_FixedLengthMessage(0x41);
Card1 kCmd_Upload(0x42);
Card1 kCmd_VariableLengthMessage(0x43);
Card1 kCmd_GetChecksum(0x44);
Card1 kCmd_EventReport(0x45);
Card1 kCmd_Mask(0x46);
Card1 kCmd_SimulatedEvent(0x47);
Card1 kCmd_GetVersion(0x48);
Card1 kCmd_DebugReport(0x49);
Card1 kCmd_X10ByteReceived(0x4A);
Card1 kCmd_InsteonMessageReceived(0x4F);
EndLiterals;
Members=
USBHID m_USB;
MemBuf m_IOBuf;
String m_Path;
Time m_Time;
#BeginDebug
ConsoleOutStream m_Con;
#EndDebug
EndMembers;
//
// Constructor and an entry point for testing purposes
//
Methods=[Public,Final]
Constructor() : m_IOBuf(8, 8);
Begin
EndConstructor;
Method Start() Returns Int4
Begin
Simulate();
Return 0;
EndMethod;
EndMethods;
//
// Helper methods for reading, writing, and parsing messages
//
Methods=[Private,Final]
Method InitIoBuffer([In] Card1 Byte1,
[In] Card1 Byte2,
[In] Card1 Byte3,
[In] Card1 Byte4,
[In] Card1 Byte5,
[In] Card1 Byte6,
[In] Card1 Byte7,
[In] Card1 Byte8)
Begin
m_IOBuf.SetAll(0);
m_IOBuf.PutCard1At(0, Byte1);
m_IOBuf.PutCard1At(1, Byte2);
m_IOBuf.PutCard1At(2, Byte3);
m_IOBuf.PutCard1At(3, Byte4);
m_IOBuf.PutCard1At(4, Byte5);
m_IOBuf.PutCard1At(5, Byte6);
m_IOBuf.PutCard1At(6, Byte7);
m_IOBuf.PutCard1At(7, Byte8);
EndMethod;
Method WriteIoBuffer()
Begin
#BeginDebug
m_Con.FmtStr("S:");
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(0), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(1), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(2), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(3), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(4), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(5), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(6), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(7), Radices.Hex);
m_Con.NewLn();
m_Con.Flush();
#EndDebug
m_USB.Write(m_IOBuf, 8, 2000);
EndMethod;
Method ReadIoBuffer() Returns Boolean
Begin
If (m_USB.Read(m_IOBuf, 8, 100, False))
#BeginDebug
m_Con.FmtStr("R: ");
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(0), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(1), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(2), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(3), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(4), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(5), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(6), Radices.Hex);
m_Con.FmtStr(" 0x");
m_Con.FmtCard1R(m_IOBuf.GetCard1At(7), Radices.Hex);
m_Con.NewLn();
m_Con.Flush();
#EndDebug
Return True;
EndIf;
Return False;
EndMethod;
Method CheckStatus() Returns Boolean
Begin
InitIoBuffer(2, kCmd_STX, kCmd_GetVersion, 0, 0, 0, 0, 0);
WriteIoBuffer();
Return False;
EndMethod;
EndMethods;
//
// Overrides of required methods defined by our base class. We must implement
// these or the compiler will complain. These are how the underlying driver
// infrastructure calls us to let us know events have occured.
//
Methods=[Public,Overrides,Final]
//
// This is called when we are first loaded. It is just for us to do any
// data initialization, to register our fields, set our poll times, and
// so forth. Here we are checking to see if the PowerLinc is present in
// the system.
Method InitializeOther([In] MEng.String CfgString, [In] MEng.System.Runtime.NamedValMap PromptVals) Returns DrvInitRes
Begin
If (!m_USB.FindDevice(kVendorId, kProductId, m_Path))
If (GetVerboseLevel() >= VerboseLvls.Medium)
LogMsg("The Insteon PowerLinc Controller is not present");
EndIf;
#BeginDebug
m_Con.FmtStr("The Insteon PowerLinc Controller is not present\n");
m_Con.Flush();
#EndDebug
Return DrvInitRes.Failed;
EndIf;
#BeginDebug
m_Con.FmtStr("Insteon PowerLinc Controller found.\nPath=");
m_Con.FmtStr(m_Path);
m_Con.NewLn();
m_Con.Flush();
#EndDebug
Return DrvInitRes.WaitCommRes;
EndMethod;
Method GetCommResource() Returns Boolean
Begin
Try
m_USB.Open(kVendorId, kProductId);
EndTry;
Catch
If (GetVerboseLevel() >= VerboseLvls.Medium)
LogMsg($Exception.GetErrorText());
EndIf;
#BeginDebug
m_Con.FmtStr("Failed to open USB port\n");
m_Con.Flush();
#EndDebug
Return False;
EndCatch;
#BeginDebug
m_Con.FmtStr("Opened USB port\n");
m_Con.Flush();
#EndDebug
Return True;
EndMethod;
Method Connect() Returns CommResults
Begin
CheckStatus();
Return CommResults.Success;
EndMethod;
Method Poll() Returns CommResults
Begin
Return CommResults.Success;
EndMethod;
Method CardFldChanged([In] Card4 FldId, [In] Card4 ValWritten) Returns CommResults
Begin
Return CommResults.Success;
EndMethod;
Method FreeCommResource() Returns Boolean
Begin
m_USB.Close();
Return True;
EndMethod;
EndMethods;