Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Error USB -----> RS232

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR
View previous topic :: View next topic  
Author Message
vanphu

Bascom Member



Joined: 27 Jul 2009
Posts: 93

vietnam.gif
PostPosted: Mon Nov 07, 2011 6:29 am    Post subject: Error USB -----> RS232 Reply with quote

Hi everybody,
I have problem to ask.
I used USB - RS232 convert cable to communication between AVR and PC ( used Visual Basic 6 software). But The VB6 software can't read data of AVR sent to PC.
But when I don't use this cable, I tried use communication COM cable so the VB6 can read data.
Do you know why?



Thanks

_________________
Best Regards
Van Phu
Back to top
View user's profile
amirf

Bascom Member



Joined: 25 Aug 2009
Posts: 154

indonesia.gif
PostPosted: Mon Nov 07, 2011 9:45 am    Post subject: Reply with quote

hi vanphu ,
i am using FTDI USB to RS232 Converter (RS232 TTL level) using VCP driver and its working !
use also with VB6 with mscom32 control with no problem ...
Back to top
View user's profile
vanphu

Bascom Member



Joined: 27 Jul 2009
Posts: 93

vietnam.gif
PostPosted: Tue Nov 08, 2011 7:59 am    Post subject: Reply with quote

Hi amirf,
I tried use program to read data from AVR send to PC.
When I use USB to RS232 cable it's work but the data not display.
When I use Com cable its work and the data display.

_________________
Best Regards
Van Phu
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 552

germany.gif
PostPosted: Tue Nov 08, 2011 9:21 pm    Post subject: Reply with quote

did you try to reduce the Baudrate? first try with 9600 Bd...
_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2473
Location: Queensland

australia.gif
PostPosted: Tue Nov 08, 2011 10:30 pm    Post subject: Reply with quote

This is a bit off-topic for Bascom, should probably be moved to forum Various but a couple of comments:

First, are you sure your USB-RS232 adapter works at all ? Did you try with just a serial terminal program like Hyperterminal, or better RealTerm.

Second, we had variable results with adapters of different USB chipsets. FDTI ones seem to work really well, some others needed playing with buffering and speed in the USB device manager section of Windows control panel, others, for instance Belkin, we could not get to work properly at all, would work for short single strings in a terminal, but drop characters and so on with long transfers into VB.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Tue Nov 08, 2011 10:31 pm    Post subject: Reply with quote

Quote:
When I use USB to RS232 cable it's work but the data not display.

How should we understand this?
Have you looked what is the number of COM port that the cable had created on PC?
Have you used exactly this number in your VB?
Back to top
View user's profile
vanphu

Bascom Member



Joined: 27 Jul 2009
Posts: 93

vietnam.gif
PostPosted: Wed Nov 09, 2011 1:53 pm    Post subject: Reply with quote

Hi everybody,
When I use the computer Win XP so
I tried one more but it's work not good,
I used USB - RS232 cable to communication with PC and I used Hyperterminal program or Labview, it's work very good.
All parameter not change
But when I try use VB6 to read data so it's work not good.

When I use the computer Windown 7 so VB6 can't read data.

I only have problem with VB.

This is the code.

$regfile = "m32def.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 32
$framesize = 64
$baud = 9600

Dim A As Byte , B As Byte
Print "ONLINE" ;
Waitms 10

Do
Print "A" ; A;
Incr A
Waitms 5
Print "B" ; B ;
Incr B
Waitms 5

Loop
End

VB6--------------------
Private Sub Form_Load()
With MSComm1
.Settings = "9600,N,8,1"
.CommPort = 1
.RThreshold = 1
.SThreshold = 0
'.InputMode = comInputModeBinary
.InputLen = 0
.Handshaking = comNone
.InBufferSize = 1024
.OutBufferSize = 1024
If .PortOpen = False Then
.PortOpen = True
End If
End With
End Sub


Private Sub MSComm1_OnComm()
'If MSComm1.CommEvent = comEvReceive Then
Data = mcscomm1.Input

Label3.Caption = Data

'End If
If Data = "ONLINE" Then Form1.Caption = "ONLINE"
If Mid(Data, 1, 1) = "A" Then Text1.Text = Mid(Data, 2, Len(Data))
If Mid(Data, 1, 1) = "B" Then Text2.Text = Mid(Data, 2, Len(Data))
Form1.Refresh
End Sub

_________________
Best Regards
Van Phu
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2473
Location: Queensland

australia.gif
PostPosted: Wed Nov 09, 2011 9:55 pm    Post subject: Reply with quote

When you say it 'work not so good' what do you really mean.

Do you get anything at all ?
Do you get non-ascii characters ?
Do you only get the first character in the input ?
Do you get characters, but miss some of them ?

Comport 1 is a really unusual port assignment for a USB adapter. I am not saying it cannot happen, but are you sure that is the right port number ?

From memory, VB receives data as single characters, and you have to concatenate them into a string before you can use them. I could be wrong here, its a long time since I used VB ( or really the MSComm control ).

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
vanphu

Bascom Member



Joined: 27 Jul 2009
Posts: 93

vietnam.gif
PostPosted: Thu Nov 10, 2011 5:04 pm    Post subject: Reply with quote

Hi AdrianJ,
I sure the comport number right.

Example:
I use [ print "ONLINE" ] command then use VB6 to get the this characters.
But when the VB6 only get "O" or "N" or "L" or "I",... characters.

case I used the computer Windown 7, The VB6 can't get characters. It's have error "Run - time error '424' ; Object required"

_________________
Best Regards
Van Phu
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2473
Location: Queensland

australia.gif
PostPosted: Thu Nov 10, 2011 10:45 pm    Post subject: Reply with quote

As I know it, VB only gets one character at a time from MSComm1.input. You have to put the characters together into a string. I am no expert on VB, and have not used it for years, look in the Help on how to do this. I suppose its something like:

char = MSComm1.input 'get the character
myString = myString & char 'concat character onto string

When you find the last character, end the string, and process it.


On Win 7, it sounds like you are missing the entire MSComm1 control - hence the error - 'object required'. I have no idea how Win 7 handles installation of what VB needs to run its programs.

I also noticed you have a typo in your code:
Quote:

Private Sub MSComm1_OnComm()
'If MSComm1.CommEvent = comEvReceive Then
Data = mcscomm1.Input

If you are using the MSComm1 control, then your input should be MSComm1.input, not mcscomm1.input, that is a different serial comms control.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
vanphu

Bascom Member



Joined: 27 Jul 2009
Posts: 93

vietnam.gif
PostPosted: Sat Nov 12, 2011 1:37 am    Post subject: Reply with quote

Hi AdrianJ,
I tried a gain but its not change and as old.

_________________
Best Regards
Van Phu
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2473
Location: Queensland

australia.gif
PostPosted: Sun Nov 13, 2011 11:40 pm    Post subject: Reply with quote

If you can receive characters from the AVR side to a PC running a terminal program, then your problem is the VB end. You will have to read more on how to use the MSComm control in VB. I cant help you there, but there is plenty of info on how to use that on the 'net, even on the Microsoft website and knowledgebase.
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
vanphu

Bascom Member



Joined: 27 Jul 2009
Posts: 93

vietnam.gif
PostPosted: Tue Nov 15, 2011 12:47 pm    Post subject: Reply with quote

Hi AdrianJ,
Thank you very much.
I only know the VB.
I will study to VB.net then ask you.
Thanks

_________________
Best Regards
Van Phu
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2473
Location: Queensland

australia.gif
PostPosted: Tue Nov 15, 2011 10:52 pm    Post subject: Reply with quote

Sorry, I think you misunderstood my abbreviation. I did not mean VB.net, I meant that you should look up the details of using the MSComms control under Visual Basic on the Internet ( World Wide Web ).

For instance, here is the Microsoft support link:
http://support.microsoft.com/kb/194922

There are many other articles from other sources about this, but not all of them are useful or correct.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
vanphu

Bascom Member



Joined: 27 Jul 2009
Posts: 93

vietnam.gif
PostPosted: Thu Nov 17, 2011 3:42 am    Post subject: Reply with quote

Hi AdrianJ,
Thank you help me.
Now I using the SCOMM32.OCX control.
It's doesn't has problem.

_________________
Best Regards
Van Phu
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum