Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com 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.

How to send two bytes in VB6 interface?

Status
Not open for further replies.

kas1

Junior Member level 3
Joined
Jun 4, 2009
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,480
hi
i need to send two bytes(Address and the instructions) from the serial port when i click a command button in VB6 interface.how can i do that? lets say i have a text box to give the address. when i click the command button first the value in the text box should go through the serial port and after few seconds the instruction byte should be transmitted. anyone please help me
 

make8 mikroc

i hope you might be knowing how to add Serial port component in your project.this component is available in MSCOMM dialog tool.you will get a telephone symbol in your tool box.add that to project.you have to set properties for your serial port component like baud rate,no of bits,COM port etc., you can set that either in properties window or in code

check this code.it does what u want

Code:
Private Sub Command1_Click()
     If MSCOMM1.PortOpen = False Then MSCOMM1.PortOpen = True
     MSCOMM1.Output = Text1.Text  
     ' make a required delay by using for loop
     MSCOMM1.Output = (your instruction here)
End Sub

Private Sub Form_Load()
 
    If  MSComm1.PortOpen Then  MSComm1.PortOpen = False
    'set the active serial port
     MSComm1.CommPort = 1
    'set the badurate,parity,databits,stopbits for the connection
     MSComm1.Settings = "9600,N,8,1"
    'set the DRT and RTS flags
     MSComm1.DTREnable = True
     MSComm1.RTSEnable = True
    'enable the oncomm event for every received character
     MSComm1.RThreshold = 1
    'disable the oncomm event for send characters
     MSComm1.SThreshold = 0
    'open the serial port
     MSComm1.PortOpen = True
 
End Sub


i thing you have opened three threads for similar vb question.make your further questions in this thread.i hope i have helped you
 

how to send 2 byte mscomm1.output

hi
thanx for the reply
Private Sub Command1_Click()
If MSCOMM1.PortOpen = False Then MSCOMM1.PortOpen = True
MSCOMM1.Output = Text1.Text
' make a required delay by using for loop
MSCOMM1.Output = (your instruction here)
End Sub

here how can i make a delay of 1000ms by using a loop? please send me the loop code
thanx
 

what is a two byte instruction

you can use timer to produce accurate Delay.Add Timer component in project

Code:
'Declare a variable
Dim Delay_flag as Boolean

in  form_load event  add 
Delay_flag=False
Timer1.interval=1000 'it's in milli second
Timer1.enable=False

in Button1_click event add
Timer1.enable=True
while Delay_Flag=false       'wait until delay_flag is made true in Timer routine
wend
Delay_flag=false               'clear the flag for another event

in Timer1_Timer() event add  'set a flag indicating a completion of delay
Timer1.enable=false
Delay_flag=True


please click helped button
 

mscomm1

hi!
i need to send the 2 bytes via serial port when i click cmdsend button.
this i my code under cmdsend event

MSComm1.Output = Chr$(160)
MSComm1.Output = Chr$(170)

after sending these two bytes should be stored in two variables in the microcontroller. here is my code for microcontroller

do {

if (Usart_Data_Ready())
{
k=Usart_read();
i = Usart_Read();
portd=i;
porta=k;
}
} while (1);

but this is not working properly. every time i send this the pic read them but not as intended.the variables are showing 160 and 170 changingly. its like a synchronization error. can anyone help me please
 

mikroc send two bytes

Code:
do {

if (Usart_Data_Ready())
{
k=Usart_read();
i = Usart_Read();
portd=i;
porta=k;
}
} while (1);

in the above code you just receiving two bytes continuously.. how do you know which byte u receiving first.. make some packet like structure to send a data from PC..
|| start byte || first byte || second byte || end packet ||
this synchronize the data send from pc to microcontroller...

and another thing u checking Usart_Data_Ready() only once and reading two byte.. check Usart_Data_Ready() before each Usart_Read()
 

utilisation des bitfields mikroc

Hi
The best way i found in MCU communication is the interrupt driven serial communication, i user int driven comm for initialization once confirmed then use pooling for each page.
 

mscomm1.portopen = true not found

this can be done by assigning the incoming three bytes to a 'long' and Accessing individual bytes for seperate variables no.
how can i access individual bytes from a "long" in microc?
pleas send me a sample code

Added after 34 minutes:

unsigned long j;
j=usart_read;

this code is note taking the incoming 4 bytes from the serial port to variable j. instead it only takes the first incoming byte to the variable j. is there anyway of getting incoming 4 bytes to a long variable in microc?
please help me
 

mscomm.output byte

there are functions in CCS to merge 8 bit variables in to long variable and to seperate long variable in to 8 bit variables.. i.e., Make32(),Make8()... i don't know about MikroC ...

better you write your own code using Bit-Fields
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top