Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] C# USB transmit error

Not open for further replies.


Full Member level 3
Sep 1, 2015
Reaction score
Trophy points
Activity points
I simulate a scenario to interface PIC18F4550 with USB by C# but when I transmit a string from my laptop to PIC the received data include some 0xFF byte :sad:. I download USB display link librabry (.dll) on the Internet. Now I cannot fix it. Anyone can help me. unexpected result.PNG

Zip and post the complete mikroC PRO project files, Proteus file and USB HID VC# application. Also mention which USB HID component like EasyUSBHIDNetClass.dll or mcHID.dll you are using.
HIDlib.dll that is the USB HID component I use, in the vc folder I attached, you can download and see it. This is all of my file (MikroC, Proteus, VC#)


  • My File.rar
    207 KB · Views: 66
Last edited by a moderator:

Hi BiNa2605

I don't have Visual Studio installed on my system. So, please make the VC# project into a setup file so that I can install it on x64 system. From the mikroC Code all I understand is that if you send 111 from USB HID Terminal then the device will display ADC value on LCD.

When I checked on the ReadADC checkbox, MCU will receive the value from variable reisistor. The problem in here is when I put the text on the TextBox, MCU receive the wrong information because it include the unexpected values, 0XFF. I send you my setup file. Because this is the first I build setup file so the direction of file not clear. You can follow the direct in my folder that I give you. Setup1\Setup1\Express\DVD-5\DiskImages\DISK1\program files\Microsoft\My Product Name

This is a attached file


  • vc.rar
    846.1 KB · Views: 53

What is the problem you are facing ? Is your problem with mikroC HID Terminal or VC# application ? Should the dll you provided placed in windows\system32 folder ? There was a problem with the oscillator configuration and I fixed it and now LCD displays the moving message but ADC value doesn't display but data sent from mikroC HID Terminal is displayed on LCD.

See attached image. It shows text sent from mikroC HID Terminal is displayed on LCD.


  • usb hid.png
    usb hid.png
    71.4 KB · Views: 78
Last edited:
Yes Sir,

The MikroC USB Terminal is work well with my project, I tried this before. I mean the VC# application, that is my problem. I send the same text like you "BiNa" but the on the display on LCD and on MikroC USB Terminal the result receive some unexpected results like this. Capture1.PNG

Ok. I will check the VC# code but please compile VC# app and make it an installable app and attach it here. I don't have VC# installed on my PC and hence cannot build it and test it. Please make a setup file which can be used to install the VC# app on my PC.
Yes Sir,

I have attached it before in the "vc.rar". You can follow the direction in the folder to find the setup file:vc\WindowsFormsApplication1\Setup1\Setup1\Express\DVD-5\DiskImages\DISK1

This is an attached file including setup file.


  • vc.rar
    846.1 KB · Views: 39

I have fixed the mikroC code and not it works. I have added this piece of code in mikroC to extract the string. Try the attached .hex file.

j = 0;
   k = 0;
   while(writebuff[k]) {
        if(((writebuff[k] >= '0') && (writebuff[k] <= '9') || ((writebuff[k] >= 'a') && (writebuff[k] <= 'z')) || ((writebuff[k] >= 'A') && (writebuff[k] <= 'Z'))))
        str[j++] = writebuff[k];
   str[i] = '\0';

In the VC# code see if changing this

System.Buffer.BlockCopy(strNull.ToCharArray(), 64-str.Length, bytes, 64-str.Length, 64);

to this solves the problem.

System.Buffer.BlockCopy('\0', 64-str.Length, bytes, 64-str.Length, 64);


  • ADC+USB+LCD+CSharp modified.rar
    41.7 KB · Views: 44
  • usb hid rev3.png
    usb hid rev3.png
    63.2 KB · Views: 71
I don't know why it doesn't work in my PC Sir :sad::sad: I will check this next on tomorrow. How can I use this code
System.Buffer.BlockCopy( null, 64 - str.Length, bytes, 64 - str.Length, 64);
instead of this code
System.Buffer.BlockCopy('\0', 64-str.Length, bytes, 64-str.Length, 64);
is not suitable in my program.
Did you solve this problem?

Forget about changing this.

System.Buffer.BlockCopy( null, 64 - str.Length, bytes, 64 - str.Length, 64);

It will not work. I tried in VC# 2010.


if(((writebuff[k] >= '0') && (writebuff[k] <= '9') || ((writebuff[k] >= 'a') && (writebuff[k] <= 'z')) || ((writebuff[k] >= 'A') && (writebuff[k] <= 'Z'))))


if((writebuff[k] >= 32) && (writebuff[k] <= 126))

in mikroC code that I posted in post #10. It works. See the image in post #10.
Last edited:
Yes Sir, It worked. :razz::razz::-D:-D

- - - Updated - - -

Now I keep gooing on the receive data from MCU and display on VC#. If I struck in diffcult things, could you mind to support me?

Yes, I will help you with your USB HID application but please provide link for documentation if the USB HID component you are using.
Dear Sir,
I continue with the receive part of communication between PIC and USB. But when I receive the string from PIC, the result display on C# is OK on the first time but after that these later results includes the value from the data of readbuff[].
send and receive.PNG
This is my attached file


  • PIC USB C#.rar
    905.1 KB · Views: 60

After each reception of data from PIC insert a 2 sec delay and clear the LCD.
Did you test it?
It is not work for my case sir.

I compioled your project and the .hex file generated by my Compiler doesn't match with your Compiler generated .hex file. I am attaching the project after compiling. The MyProject.hex file is mine and the Copy version is yours.


  • ADC+USB+LCD+CSharp.rar
    131.7 KB · Views: 46
Last edited by a moderator:
Dear Sir,

The file you sent me has the same result so that I think that compiler is not a problem. When I clicked on the Receive button before Send button on GUI VC# the program is strucked. I think the problem is another thing.
Last edited by a moderator:

Maybe it is not programmed to handle empty testbox. I will check the VC# code.

Not open for further replies.

Part and Inventory Search

Welcome to