When i use pwm controller 13, usb cdc does not work, what’s up with that?
Are you sure? Have you tried in a small example that has nothing else but CDC and Controller13?
Ive tested to remove everything and only CDC and this class.
If all is uncomented it does not work, if any one of the PwmConrtollers is commented it works
class Controllers
{
public PwmController Pwm1 { get; set; }
//public PwmController Pwm2 { get; set; }
public PwmController Pwm3 { get; set; }
public PwmController Pwm13 { get; set; }
public I2cController I2c { get; set; }
public Controllers()
{
I2c = I2cController.FromName(SC20100.I2cBus.I2c1);
Pwm1 = PwmController.FromName(SC20100.PwmChannel.Controller1.Id);
//Pwm2 = PwmController.FromName(SC20100.PwmChannel.Controller2.Id);
Pwm3 = PwmController.FromName(SC20100.PwmChannel.Controller3.Id);
Pwm13 = PwmController.FromName(SC20100.PwmChannel.Controller13.Id);
Pwm1.SetDesiredFrequency(1000);
//Pwm2.SetDesiredFrequency(1000);
Pwm3.SetDesiredFrequency(1000);
Pwm13.SetDesiredFrequency(1000);
}
}
Here is a small example
class Program
{
static UsbClientController usbClient;
static PwmController Pwm13;
static PwmController Pwm3;
static PwmController Pwm1;
static PwmController Pwm2;
static void Main()
{
Pwm13 = PwmController.FromName(SC20100.PwmChannel.Controller13.Id);
Pwm3 = PwmController.FromName(SC20100.PwmChannel.Controller3.Id);
Pwm2 = PwmController.FromName(SC20100.PwmChannel.Controller2.Id);
Pwm1 = PwmController.FromName(SC20100.PwmChannel.Controller1.Id);
Pwm13.SetDesiredFrequency(1000);
Pwm3.SetDesiredFrequency(1000);
Pwm2.SetDesiredFrequency(1000);
Pwm1.SetDesiredFrequency(1000);
usbClient = UsbClientController.GetDefault();
UsbClientSetting usbClientSetting = new UsbClientSetting()
{
Mode = UsbClientMode.Cdc,
ManufactureName = "123",
ProductName = "1234",
SerialNumber = "12345",
Guid = "A4469079-5D49-4622-B3BC-071C55106446",
ProductId = 0x1234,
VendorId = 0x5678,
};
usbClient.SetActiveSetting(usbClientSetting);
usbClient.DataReceived += UsbClient_DataReceived;
usbClient.Enable();
Thread.Sleep(Timeout.Infinite);
}
private static void UsbClient_DataReceived(UsbClientController sender, uint count)
{
byte[] receiveBuffer = new byte[count];
int bytesReceived = sender.Read(receiveBuffer, 0, (int)count);
string data = Encoding.UTF8.GetString(receiveBuffer, 0, bytesReceived);
Debug.WriteLine(data);
}
}
Can someone please test this?
You posted on weekend and it is 9am Monday morning now. Can we get some coffee first please?
Yeah, sorry. But don’t you work on weekends?
We do. I did answer you on Sunday but I didn’t have a board to test
Can someone please check this?
We didn’t forget but we are very busy with critical issues.
Hi, your example is very old and sorry we couldn’t go back to find the issue.
We tried in preview4 and no issue found. Here is your project rewrite in Preview4.
static UsbClientController usbClient;
static PwmController Pwm13;
static PwmController Pwm3;
static PwmController Pwm1;
static PwmController Pwm2;
static void DoTestCdcPwm()
{
Pwm13 = PwmController.FromName(SC20260.Timer.Pwm.Controller13.Id);
Pwm3 = PwmController.FromName(SC20260.Timer.Pwm.Controller3.Id);
Pwm2 = PwmController.FromName(SC20260.Timer.Pwm.Controller2.Id);
Pwm1 = PwmController.FromName(SC20260.Timer.Pwm.Controller1.Id);
Pwm13.SetDesiredFrequency(1000);
Pwm3.SetDesiredFrequency(1000);
Pwm2.SetDesiredFrequency(1000);
Pwm1.SetDesiredFrequency(1000);
var usbclientController = UsbClientController.GetDefault();
var usbClientSetting = new UsbClientSetting()
{
Mode = UsbClientMode.Cdc,
ManufactureName = "Manufacture_Name",
ProductName = "Product_Name",
SerialNumber = "12345678",
};
var cdc = new Cdc(usbclientController, usbClientSetting);
cdc.DeviceStateChanged += (a, b) => Debug.WriteLine("Connection changed.");
cdc.DataReceived += (a, count) => Debug.WriteLine("Data received:" + count);
cdc.Enable();
while (cdc.DeviceState != DeviceState.Configured) ;
Debug.WriteLine("UsbClient Connected");
// The example will read data from port to dataR array
// Copy dataR to dataW array, plus 1 for each element
// Write dataW array back to port
while (true)
{
var len = cdc.Stream.BytesToRead;
if (len > 0)
{
var dataR = new byte[len];
var dataW = new byte[len];
int read = cdc.Stream.Read(dataR);
for (var i = 0; i < read; i++)
{
dataW[i] = (byte)(dataR[i] + 1);
}
cdc.Stream.Write(dataW);
}
Thread.Sleep(100);
}
}
Ok, ill use preview4, if you wont go back then it should be good enough
was planning to use WebUSB anyway, but was waiting on RTW
yes, try P4 and let us know if something that need to be fixed.
Thanks
That is different thing. You need to restart the device in serial mode.
There is mod button or tight pd7 to GND then reset the device.
You are one of the experts by now. These questions are not allowed at your level
Im not following this. This behavior has then changed.
So here were the steps before:
- Upload code (the device did some things and enabled itself for usb pc communication)
- I pushed reset
- I could then connect to PC and with a PC app change some things about the device
- To upload new code pushed APP+RESET
With each reset the device did work and was available for PC communication.
If i wanted to upload code again i could do so with Serial (MOD pin) or pushed APP+RESET to not load the current app and then reuploaded my new app.
How things now work:
When i upload code which enables usb client, after reset the app does not work nor the debugger.
Until i restart with mod pin low.
So i did not design my board to have a switch, it has a button for mod pin.
How am i suppose to use USB client now?
Same as before but before the firmware allowed you to create a usb controller and now you can only do it if the USB port is free. It was wrong before.
You can still do what you did before.
The goal is:
Using same USB for Client and Debugger for debugger to have to do special to use it (like unload the app) and a Usb Client to do absolutely nothing.
When i ship a device i don’t want a customer to push a button (mod pin) to be able to access device with PC. I dont mind doing so when i program it.
But i didnt design it with a DIP switch