none
如何用RS232 控制投影機 RRS feed

  • 問題

  • 各位大大好:
    小弟手上剛好有個需求是要透過RS232去控制投影機,投影機的型號為ViewSonic PJ658,有跟ViewSonic要此機器的RS232控制碼,但怎麼試投影機就是沒動作,想請教各為大大有無做過類似的控制?
    這是文件中控制開關機的控制碼:
    Turn off : BE EF 03 06 00 2A D3 01 00 00 60 00 00
    Turn on : BE EF 03 06 00 BA D2 01 00 00 60 01 00

    若是成功回收到"06H",若是送錯控制碼則收到"15H",但是我怎麼送都是不會動作也收不到任何回覆回來的訊息,
    下面就是我操作的code,麻煩請教各位大大是我寫錯了?還是該怎麼控制呢?謝謝

        Public myRS232 As SerialPort = New SerialPort
        Dim controlbyte(13) As Byte
    
    
        Public Sub iniPort()
            '初始化RS232連接埠
    
            myRS232.BaudRate = 19200
            myRS232.DataBits = 8
            myRS232.StopBits = StopBits.One
            myRS232.PortName = "COM5"
        End Sub
    
    
        '開機
        Private Function PowerOn() As String
            Dim strsend As String
            controlbyte(0) = &HBE
            controlbyte(1) = &HEF
            controlbyte(2) = &H3
            controlbyte(3) = &H6
            controlbyte(4) = &H0
            controlbyte(5) = &HBA
            controlbyte(6) = &HD2
            controlbyte(7) = &H1
            controlbyte(8) = &H0
            controlbyte(9) = &H0
            controlbyte(10) = &H60
            controlbyte(11) = &H1
            controlbyte(12) = &H0
            For i = 0 To 12
                strsend = strsend & controlbyte(i)
    
            Next
            Return strsend
        End Function
    
        '關機
        Private Function PowerClose() As String
            Dim strsend As String
            controlbyte(0) = &HBE
            controlbyte(1) = &HEF
            controlbyte(2) = &H3
            controlbyte(3) = &H6
            controlbyte(4) = &H0
            controlbyte(5) = &H2A
            controlbyte(6) = &HD3
            controlbyte(7) = &H1
            controlbyte(8) = &H0
            controlbyte(9) = &H0
            controlbyte(10) = &H60
            controlbyte(11) = &H0
            controlbyte(12) = &H0
            For i = 0 To 12
                strsend = strsend & controlbyte(i)
            Next
            Return strsend
    
        End Function
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            iniPort()
            If myRS232.IsOpen = False Then
                myRS232.Open()
            End If
    
        End Sub
    
        Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    
            myRS232.Write(PowerClose)
            Thread.Sleep(3)
            Dim strread As String = myRS232.ReadExisting()
    
            '收到06H表示成功
            If strread = "6" Then
                MessageBox.Show("關機成功")
            End If
        End Sub
    
        Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
            Dim strdata As String = PowerOn()
    
    
            myRS232.Write(strdata)
    
            Thread.Sleep(40)
            Dim strread As String = myRS232.ReadExisting()
    
            '收到06H表示成功
            If strread = "6" Then
                MessageBox.Show("開機成功")
            End If
        End Sub


    2009年11月13日 上午 02:29

解答

所有回覆