|
板凳
樓主 |
發(fā)表于 2012-8-24 09:09:38
|
只看該作者
dddg 發(fā)表于 2012-8-23 15:03
搞什么? 通信通沒(méi)通?沒(méi)通說(shuō)個(gè)P先搞通再說(shuō),通了說(shuō)個(gè)p隨便怎么定義。
多謝您,上位機(jī)的程序是:
Public Const stopX = &H0
Public Const moveX = &H1
Public Const JogPX = &H2
Public Const JogNX = &H3
Public Const PosX = &H4
Public Const stopY = &H10
Public Const moveY = &H11
Public Const JogPY = &H12
Public Const JogNY = &H13
Public Const PosY = &H14
Public Const moveC = &HB0
Public Const moveN = &HB1
Public Const SetPWM = &HC0
Public Const SetIO = &HC1
Public Const SetRERX = &HC2
Public Const SetRERY = &HC3
Public Const SetSonX = &HC4
Public Const SetSonY = &HC5
Public Const RstFLG = &HC6
Public Const SetHdrFlg = &HC7
Public Sub RegSetIO(ByVal port As Byte, ByVal status As Byte)
Dim sbuf(3) As Byte
sbuf(0) = SetIO
sbuf(1) = port
sbuf(2) = status
frmMain.MSComm1.Output = sbuf
End Sub
Private Sub cmdHdrGo_Click()
fraPass.Visible = False
If HeadUp = True Then
HeadUp = False
RegSetIO 9, 0 'A
RegSetIO 10, 0 'B
RegSetIO 11, 0 'C
RegSetIO 12, 0 'D
Else
HeadUp = True
If chkHeaderA.Value Then RegSetIO 9, 1 'A
If chkHeaderB.Value Then RegSetIO 10, 1 'B
If chkHeaderC.Value Then RegSetIO 11, 1 'C
If chkHeaderD.Value Then RegSetIO 12, 1 'D
End If
End Sub
下位機(jī)的程序
void Set_IO(unsigned char index,unsigned char sbit)
{ switch(index)
{
case 1:
GPIO_WriteBit(GPIOA,GPIO_Pin_4,sbit);
break;
case 2:
GPIO_WriteBit(GPIOA,GPIO_Pin_5,sbit);
break;
case 3:
GPIO_WriteBit(GPIOA,GPIO_Pin_6,sbit);
break;
case 4:
GPIO_WriteBit(GPIOA,GPIO_Pin_7,sbit);
break;
case 5:
GPIO_WriteBit(GPIOB,GPIO_Pin_0,sbit);
break;
case 6:
GPIO_WriteBit(GPIOB,GPIO_Pin_1,sbit);
break;
case 7:
GPIO_WriteBit(GPIOB,GPIO_Pin_6,sbit);
break;
case 8:
GPIO_WriteBit(GPIOB,GPIO_Pin_7,sbit);
break;
case 10: case 9:
GPIO_WriteBit(GPIOB,GPIO_Pin_8,sbit);
break;
GPIO_WriteBit(GPIOB,GPIO_Pin_9,sbit);
break;
case 11:
GPIO_WriteBit(GPIOB,GPIO_Pin_10,sbit);
break;
case 12:
GPIO_WriteBit(GPIOB,GPIO_Pin_11,sbit);
break;
case 13:
GPIO_WriteBit(GPIOB,GPIO_Pin_12,sbit);
break;
case 14:
GPIO_WriteBit(GPIOB,GPIO_Pin_13,sbit);
break;
case 15:
GPIO_WriteBit(GPIOB,GPIO_Pin_14,sbit);
break;
case 16:
GPIO_WriteBit(GPIOB,GPIO_Pin_15,sbit);
break;
case 17:
GPIO_WriteBit(GPIOA,GPIO_Pin_8,sbit);
if(sbit) srdX.error_code &=0xBF;
break;
case 18:
GPIO_WriteBit(GPIOA,GPIO_Pin_9,sbit);
if(sbit) srdY.error_code &=0xBF;
break;
}
}
比如我現(xiàn)在VB中發(fā)送到下位機(jī) 執(zhí)行 RegSetIO 9, 1
然后對(duì)應(yīng)下位機(jī) case 9:
GPIO_WriteBit(GPIOB,GPIO_Pin_8,sbit);
break;
得到PB8端口輸出的發(fā)光二極管被點(diǎn)亮
反之執(zhí)行 RegSetIO 9, 0
發(fā)光二極管熄滅
我要是把Public Const SetIO = &HC1改成 Public Const SetIO = &HC9或是其他任意值
就得不到上述的結(jié)果
這個(gè)程序是以前的前輩留下來(lái)
我現(xiàn)在的疑問(wèn)是上位機(jī)發(fā)送一個(gè)指令,在下位機(jī)收到后
是怎么執(zhí)行的(控制發(fā)光二極管的亮或滅)
小弟是新手,剛剛接觸,搞了好多天,望您指教,多謝多謝!著急啊,悶了好久
|
|