|
 |
|
อยากทราบ การรับค่าจากสวิตซ์ภายนอก ของ mini2440 wince vb2008 อ่ะคับ |
|
 |
|
|
 |
 |
|
อยากทราบว่า ถ้าผมต้องการรับค่าจากสวิตซ์ภายนอก มาต่อกับ gpio mini2440 wince vb2008 เพื่อแสดงสถานะของสวิตซ์ อ่ะคับ ว่ารูปแบบคำสั่งเป็นยังไงอ่ะคับ
จาก Exsample มันใช้ checkbox อ่ะคับ
Code
If (hPort <> INVALID_HANDLE_VALUE) Then
sInput = 0
'Set pin position from CheckBox in to sInput
sInput = sInput + (Convert.ToUInt32(chkInput0.Checked) << 0) ผมต้องทำยังไงถึงจะรับค่าจากสวิตซ์ได้อ่ะคับ ที่
PORT_F_0
' Convert sInput(UInt32) to sBuf(Array of Byte)
BitConverter.GetBytes(sInput).CopyTo(sBuf, 0)
' Set pin in PORT F = Input Mode
DeviceIoControl(hPort, PORT_F Or SET_INPUT, sBuf, 4, Nothing, 0, 0, IntPtr.Zero)
End If
วานผู้รู้ช่วยตอบหน่อยคับ
ขอบคุณคับ
Tag : .NET, VB.NET, VS 2008 (.NET 3.x)

|
|
 |
 |
 |
 |
Date :
2012-03-19 05:57:02 |
By :
mo_chi |
View :
1442 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ ขั้นตอนการอ่านค่ามาจาก GPIO มีสองขั้นตอนใหญ่ๆ
1.การกำหนดให้ขาใหนเป็น input บ้างสามารถดูได้จาก event ของปุ่ม SET
2.การอ่านค่ามาจากขา input ที่ถูกเซตแล้ว ดูได้จาก event ของปุ่ม GET ครับ
โค้ดที่คุณ mochi ให้มาเป็นช่วงการกำหนดค่า
ฟังชั่นที่สำคัญคือ DeviceIoControl โดยมีพารามิเตอร์ 2 ตัวทีสำคัญ
1. PORT_F Or SET_INPUT หมายถึง กำหนดพอร์ต F ให้เป็น input
2. sBuf คือตัวแปรที่กำหนดว่าขาใหนเป็น input บ้าง
หลังจากนั้นเป็นการอ่าค่ามาจากพอร์ต F ดูที่คำสั่ง
DeviceIoControl(hPort, PORT_F Or GET_PIN, Nothing, 0, rBuf, rLen, 0, IntPtr.Zero)
พารามิเตอร์ตัวที่ 2 PORT_F Or GET_PIN คือคำสั่งอ่านค่าจากพอร์ต F
โดยค่าที่อ่านอกมาได้จะเข้าไปเก็บในอาเรย์ rBuf จึงต้องแปลงเป็นตัวเลข Int ในตัวแปร rOutput
จากนั้นจึงนำตัวแปร rOutput ไปดูว่าสถานะที่ขาต่างๆเป็นอย่างไร
Credit:http://www.thaieasyelec.com/index.php?lay=boardshow&ac=webboard_show&WBntype=1&Category=thaieasyeleccom&thispage=3&No=1351122
|
 |
 |
 |
 |
Date :
2012-09-25 18:33:41 |
By :
dekkuza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|