DerekGn / MCP2221IO

A .Net Core library to interact with MCP2221 Usb devices
MIT License
5 stars 0 forks source link

Smbus read-command #2

Closed ESharpAB closed 6 months ago

ESharpAB commented 8 months ago

Hi, This is perhaps more a question than an issue, as I might have misunderstood the usage of the library.

I'm trying to use the smbus commands (read-byte-command and read-int-command) towards a PMBUS-device on address 0x53. I try to read the 'CAPABILITY' register (0x20) but I always get "Unexpected response code".

Am I doing this wrong?

accordion@A000619:~/net6.0 $ sudo dotnet MCP2221IOConsole.dll smbus read-int-command -ia 0x53 -c 32 [05:20:29.8907447 DBG] Executed [Device].[Open] in [208.514] ms Reading an int from the SmBus device address [Value: 0x0053 Size: SevenBit] [05:20:29.9715280 DBG] Output HID Packet: [00,0x90,0x01,0x00,0xA6,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00] [05:20:29.9873360 DBG] Input HID Packet: [00,0x90,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x1B,0x00,0xEF,0x00,0x10,0x28,0x40,0x60,0x01,0x01,0x00,0x00,0xF1,0x79,0xF0,0x00,0x00,0x00,0x30,0x30,0x0B,0x30,0x2C,0x23,0x1F,0x36,0x04,0x00,0x00,0x26,0x90,0x14,0x41,0x36,0x31,0x32,0xFF,0x03,0xFF,0x03,0xFE,0x03,0x02,0x03,0x92,0x01,0x00,0x00,0x00,0x00] [05:20:29.9903788 ERR] An exception occurred executing [Device].[I2cWriteData] Reason: [Unexpected response code Expected: [0x94] Actual [0x90]] [05:20:29.9914045 ERR] An exception occurred executing [Device].[SmBusReadCommand] Reason: [Unexpected response code Expected: [0x94] Actual [0x90]] [05:20:29.9930222 DBG] Disposing Device An unhandled exception occurred: MCP2221IO.Exceptions.InvalidResponseTypeException: Unexpected response code Expected: [0x94] Actual [0x90] at MCP2221IO.Responses.BaseResponse.Deserialize(Stream stream) in C:\dev\source\MCP2221IO\MCP2221IO\Responses\BaseResponse.cs:line 65 at MCP2221IO.Device.ExecuteCommand[T](ICommand command, Boolean checkResult) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 778 at MCP2221IO.Device.<>c__DisplayClass92_01.b0() in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 731 at MCP2221IO.Device.HandleOperationExecution(String className, Action operation, String memberName) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 796 at MCP2221IO.Device.I2cWriteData[T](CommandCodes commandCode, I2cAddress address, IList`1 data) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 721 at MCP2221IO.Device.<>cDisplayClass86_0.b0() in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 597 at MCP2221IO.Device.HandleOperationExecution[T](String className, Func`1 operation, String memberName) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 818 at MCP2221IO.Device.SmBusReadCommand(I2cAddress address, Byte command, UInt16 length, Boolean pec) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 591 at MCP2221IO.Device.SmBusReadIntCommand(I2cAddress address, Byte command, Boolean pec) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 486 at MCP2221IOConsole.Commands.SmBus.SmBusReadIntCommand.<>cDisplayClass1_0.b__0(IDevice device) in C:\dev\source\MCP2221IO\MCP2221IOConsole\Commands\SmBus\SmBusReadIntCommand.cs:line 46 at MCP2221IOConsole.Commands.BaseCommand.ExecuteCommand(Func2 action) in C:\dev\source\MCP2221IO\MCP2221IOConsole\Commands\BaseCommand.cs:line 67 accordion@A000619:~/net6.0 $

Any help is appreciated. Best regards Daniel

DerekGn commented 6 months ago

Hey sorry for not responding sooner. I get so many notification from github this one got lost in the noise.

I will need to have a look at the docs again for the MCP2221 device, its been a while since I looked at this code.

DerekGn commented 6 months ago

I reformatted the trace data for better readability

accordion@A000619:~/net6.0 $ sudo dotnet MCP2221IOConsole.dll smbus read-int-command -ia 0x53  -c 32 
[05:20:29.8907447 DBG] Executed [Device].[Open] in [208.514] ms Reading an int from the SmBus device address [Value: 0x0053 Size: SevenBit] 
[05:20:29.9715280 DBG] Output HID Packet: [00,0x90,0x01,0x00,0xA6,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
[05:20:29.9873360 DBG] Input HID Packet: [00,0x90,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x1B,0x00,0xEF,0x00,0x10,0x28,0x40,0x60,0x01,0x01,0x00,0x00,0xF1,0x79,0xF0,0x00,0x00,0x00,0x30,0x30,0x0B,0x30,0x2C,0x23,0x1F,0x36,0x04,0x00,0x00,0x26,0x90,0x14,0x41,0x36,0x31,0x32,0xFF,0x03,0xFF,0x03,0xFE,0x03,0x02,0x03,0x92,0x01,0x00,0x00,0x00,0x00] 
[05:20:29.9903788 ERR] An exception occurred executing [Device].[I2cWriteData] Reason: [Unexpected response code Expected: [0x94] Actual [0x90]] 
[05:20:29.9914045 ERR] An exception occurred executing [Device].[SmBusReadCommand] Reason: [Unexpected response code Expected: [0x94] Actual [0x90]] 
[05:20:29.9930222 DBG] Disposing Device An unhandled exception occurred: MCP2221IO.Exceptions.InvalidResponseTypeException: Unexpected response code Expected: [0x94] Actual [0x90] 
at MCP2221IO.Responses.BaseResponse.Deserialize(Stream stream) in C:\dev\source\MCP2221IO\MCP2221IO\Responses\BaseResponse.cs:line 65 
at MCP2221IO.Device.ExecuteCommand[T](ICommand command, Boolean checkResult) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 778 
at MCP2221IO.Device.<>c__DisplayClass92_01.b__0() in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 731
at MCP2221IO.Device.HandleOperationExecution(String className, Action operation, String memberName) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 796
at MCP2221IO.Device.I2cWriteData[T](CommandCodes commandCode, I2cAddress address, IList1 data) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 721 
at MCP2221IO.Device.<>c__DisplayClass86_0.<SmBusReadCommand>b__0() in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 597 
at MCP2221IO.Device.HandleOperationExecution[T](String className, Func1 operation, String memberName) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 818
at MCP2221IO.Device.SmBusReadCommand(I2cAddress address, Byte command, UInt16 length, Boolean pec) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 591
at MCP2221IO.Device.SmBusReadIntCommand(I2cAddress address, Byte command, Boolean pec) in C:\dev\source\MCP2221IO\MCP2221IO\Device.cs:line 486
at MCP2221IOConsole.Commands.SmBus.SmBusReadIntCommand.<>c__DisplayClass1_0.b__0(IDevice device) in C:\dev\source\MCP2221IO\MCP2221IOConsole\Commands\SmBus\SmBusReadIntCommand.cs:line 46
at MCP2221IOConsole.Commands.BaseCommand.ExecuteCommand(Func2 action) in C:\dev\source\MCP2221IO\MCP2221IOConsole\Commands\BaseCommand.cs:line 67 accordion@A000619:~/net6.0 $
DerekGn commented 6 months ago

@ESharpAB I found a small bug in the smb method, it was validating the response code from the MCP2221A device incorrectly. Next build 2.0.0 will resolve this problem.

I have also upgraded the runtime as net app 3.1 is no longer supported by MS