PDA

View Full Version : حرفه ای: RX-TX in Windows Ce 6



MehdiElexal
یک شنبه 31 اردیبهشت 1391, 14:29 عصر
با سلام
یه دستگاه با ویندوز CE6 هست که متصل به یک Access Point هست
چطور میشه با یک لپ تاپی که به همون Access Point وصل شده رشته ارسال و دریافت کرد همانند سریال پورت ؟
اگر جای دیگه ای این بحث شده لطفا لینک بدید
ممنون

MehdiElexal
دوشنبه 01 خرداد 1391, 17:43 عصر
نظری ، مطلبی ، کمکی ، هیچــــــــــــــــــــــ ـــــــــــــــــــــــــ ی ؟

Saeed_m_Farid
دوشنبه 01 خرداد 1391, 19:25 عصر
با سلام
یه دستگاه با ویندوز CE6 هست که متصل به یک Access Point هست
چطور میشه با یک لپ تاپی که به همون Access Point وصل شده رشته ارسال و دریافت کرد همانند سریال پورت ؟
اگر جای دیگه ای این بحث شده لطفا لینک بدید
ممنون
سلام
اولاً چه ربطی داره به ویندوز CE؟ بعدش هم Access point ات این وسط چه کارست؟ میخوای با ویندوز CE6 ارتباط برقرار کنی، خوب باید با TCP یا UDP دستور بفرستی و با Listener منتظر جواب باشی! حالا وسط Access point باشه یا هرچی؛ اگه ممکنه دقیق تر بگو میخوای چکار کنی...

این هیچ ربطی به RS232 یا ویندوز CE6 و ... اینا نداره، مگه اینکه مثلاً با پورت سریال به دیوایس وصل بشی که اونوقت System.IO.Ports (http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx) استفاده میکنین و بحثش فرق میکنه (اینجا (http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx) و + (http://www.dreamincode.net/forums/topic/35775-serial-port-communication-in-c%23/))
-------------
ولی زمانی هست که حالت خاصی داری و مثلاً میخوای فقط این دستورات رو پباده سازی کنی :

* نمایش آدرس BSSID یک WAP (میدونین که دو تا آدرس داره، یکی برای دوایس وایرلس و یکی هم برای دوایس شبکه):

netsh wlan show networks mode=Bssid | findstr "BSSID"

شما مجبورید یا از IP Helper (http://msdn.microsoft.com/en-us/library/aa366073%28VS.85%29.aspx) (تابع GetIpNetTable : + (http://www.pinvoke.net/search.aspx?search=GetIpNetTable)) یا WMI (http://msdn.microsoft.com/en-us/library/aa310909%28VS.71%29.aspx) (+ (http://msdn.microsoft.com/en-us/library/aa720682%28VS.71%29.aspx)) استفاده کنید، یا از کامپوننتهای آماده، مثلاً (Managed Wifi API (http://managedwifi.codeplex.com/)) و در اینصورت یه همچین کدی جواب معماست :لبخند::


var wlanClient = new WlanClient();
foreach (WlanClient.WlanInterface wlanInterface in wlanClient.Interfaces)
{
Wlan.WlanBssEntry[] wlanBssEntries = wlanInterface.GetNetworkBssList();
foreach (Wlan.WlanBssEntry wlanBssEntry in wlanBssEntries)
{
byte[] macAddr = wlanBssEntry.dot11Bssid;
var macAddrLen = (uint) macAddr.Length;
var str = new string[(int) macAddrLen];
for (int i = 0; i < macAddrLen; i++)
{
str[i] = macAddr[i].ToString("x2");
}
string mac = string.Join("", str);
Console.WriteLine(mac);
}
}



شایدم من اصلاً نفهمیدم منظور چیه! دراینصورت روی سوال مبهم بوده چون من خیلی عاقلم :قهقهه:

MehdiElexal
چهارشنبه 03 خرداد 1391, 06:57 صبح
سلام
اولاً چه ربطی داره به ویندوز CE؟ بعدش هم Access point ات این وسط چه کارست؟ میخوای با ویندوز CE6 ارتباط برقرار کنی، خوب باید با TCP یا UDP دستور بفرستی و با Listener منتظر جواب باشی! حالا وسط Access point باشه یا هرچی؛ اگه ممکنه دقیق تر بگو میخوای چکار کنی...

این هیچ ربطی به RS232 یا ویندوز CE6 و ... اینا نداره، مگه اینکه مثلاً با پورت سریال به دیوایس وصل بشی که اونوقت System.IO.Ports (http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx) استفاده میکنین و بحثش فرق میکنه (اینجا (http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx) و + (http://www.dreamincode.net/forums/topic/35775-serial-port-communication-in-c%23/))
-------------
ولی زمانی هست که حالت خاصی داری و مثلاً میخوای فقط این دستورات رو پباده سازی کنی :

* نمایش آدرس BSSID یک WAP (میدونین که دو تا آدرس داره، یکی برای دوایس وایرلس و یکی هم برای دوایس شبکه):

netsh wlan show networks mode=Bssid | findstr "BSSID"

شما مجبورید یا از IP Helper (http://msdn.microsoft.com/en-us/library/aa366073%28VS.85%29.aspx) (تابع GetIpNetTable : + (http://www.pinvoke.net/search.aspx?search=GetIpNetTable)) یا WMI (http://msdn.microsoft.com/en-us/library/aa310909%28VS.71%29.aspx) (+ (http://msdn.microsoft.com/en-us/library/aa720682%28VS.71%29.aspx)) استفاده کنید، یا از کامپوننتهای آماده، مثلاً (Managed Wifi API (http://managedwifi.codeplex.com/)) و در اینصورت یه همچین کدی جواب معماست :لبخند::


var wlanClient = new WlanClient();
foreach (WlanClient.WlanInterface wlanInterface in wlanClient.Interfaces)
{
Wlan.WlanBssEntry[] wlanBssEntries = wlanInterface.GetNetworkBssList();
foreach (Wlan.WlanBssEntry wlanBssEntry in wlanBssEntries)
{
byte[] macAddr = wlanBssEntry.dot11Bssid;
var macAddrLen = (uint) macAddr.Length;
var str = new string[(int) macAddrLen];
for (int i = 0; i < macAddrLen; i++)
{
str[i] = macAddr[i].ToString("x2");
}
string mac = string.Join("", str);
Console.WriteLine(mac);
}
}



شایدم من اصلاً نفهمیدم منظور چیه! دراینصورت روی سوال مبهم بوده چون من خیلی عاقلم :قهقهه:





در عاقلی شما که هیچ شکی نیست اما داداش چرا انقدر حالت تحاجمی داری تو ؟ :قهقهه:
گفتم که در پست اول : یه دستگاه هست با ویندوز CE کار میکنه ، حالا میگی چه ربطی به ویندوز CE داره ، میخوای برم از کار خونش بپرسم ؟ :بامزه:
http://www.friendlyarm.net/products/mini2440
اینهم مشخصاتش

عرضم به خدمتتون بحث اکسس پوینت منظور این بود که ارتباط بصورت LAN برقرار هست (Ping)
حالا میخوام یه برنامه برای اون باشه قائدتا یکی هم برای کامپیوتر تا بتونم از سیستم به اون و بلعکس رشته یا حالا هرچی داده Rx-Tx کنم
دوست عزیز اگر بازهم گنگه دیگه منو ببخشید زبانم بیشتر از این قاصره :خجالت:

Saeed_m_Farid
چهارشنبه 03 خرداد 1391, 10:36 صبح
راست میگی، ببخشید
طرف لب تاپت که کاری نداره، فکر کنم میدونی ولی گفتنش هم اشکال نداره، برای ارتباط باید یه Socket رو یه پورت خاص به IPAddress اون سیستم CE بزنی و Bind بعد Listen و بعدش BeginAccept ...
بهتره یه Connection درست کنی و نگهداری برای Send؛ کلاً میشه یه چیزی مثل این کد:

public class Server()
{
private Socket sock;
// You'll probably want to initialize the port and address in the
// constructor, or via accessors, but to start your server listening
// on port 8080 and on any IP address available on the machine...
private int port = 8080;
private IPAddress addr = IPAddress.Any;

// This is the method that starts the server listening.
public void Start()
{
// Create the new socket on which we'll be listening.
this.sock = new Socket(
addr.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp);
// Bind the socket to the address and port.
sock.Bind(new IPEndPoint(this.addr, this.port));
// Start listening.
this.sock.Listen(this.backlog);
// Set up the callback to be notified when somebody requests
// a new connection.
this.sock.BeginAccept(this.OnConnectRequest, sock);
}

// This is the method that is called when the socket recives a request
// for a new connection.
private void OnConnectRequest(IAsyncResult result)
{
// Get the socket (which should be this listener's socket) from
// the argument.
Socket sock = (Socket)result.AsyncState;
// Create a new client connection, using the primary socket to
// spawn a new socket.
Connection newConn = new Connection(sock.EndAccept(result));
// Tell the listener socket to start listening again.
sock.BeginAccept(this.OnConnectRequest, sock);
}
}


اینم یه کلاس Connection برای دیوایسی که وصل میشه و شما ازش اطلاعات میگیری :

public class Connection()
{
private Socket sock;
// Pick whatever encoding works best for you. Just make sure the remote
// host is using the same encoding.
private Encoding encoding = Encoding.UTF8;

public Connection(Socket s)
{
this.sock = s;
// Start listening for incoming data. (If you want a multi-
// threaded service, you can start this method up in a separate
// thread.)
this.BeginReceive();
}

// Call this method to set this connection's socket up to receive data.
private void BeginReceive()
{
this.sock.BeginReceive(
this.dataRcvBuf, 0,
this.dataRcvBuf.Length,
SocketFlags.None,
new AsyncCallback(this.OnBytesReceived),
this);
}

// This is the method that is called whenever the socket receives
// incoming bytes.
protected void OnBytesReceived(IAsyncResult result)
{
// End the data receiving that the socket has done and get
// the number of bytes read.
int nBytesRec = this.sock.EndReceive(result);
// If no bytes were received, the connection is closed (at
// least as far as we're concerned).
if (nBytesRec <= 0)
{
this.sock.Close();
return;
}
// Convert the data we have to a string.
string strReceived = this.encoding.GetString(
this.dataRcvBuf, 0, nBytesRec);

// ...Now, do whatever works best with the string data.
// You could, for example, look at each character in the string
// one-at-a-time and check for characters like the "end of text"
// character ('\u0003') from a client indicating that they've finished
// sending the current message. It's totally up to you how you want
// the protocol to work.

// Whenever you decide the connection should be closed, call
// sock.Close() and don't call sock.BeginReceive() again. But as long
// as you want to keep processing incoming data...

// Set up again to get the next chunk of data.
this.sock.BeginReceive(
this.dataRcvBuf, 0,
this.dataRcvBuf.Length,
SocketFlags.None,
new AsyncCallback(this.OnBytesReceived),
this);

}
}


برای فرستادن اطلاعات رشته ای هم کافیه از کلاس Connection یه شی بسازید و
this.sock.Send(this.encoding.GetBytes("Hello to you, remote host."));

************************
البته "رشته یا حالا هرچی" اش یکمی فرق میکنه! واسه هرچی باید داده ها رو Serialize کنی، مثلاً اینطوری :

private Stream SerializeMultipleObjects()
{
// Initialize a storage medium to hold the serialized object
Stream stream = new MemoryStream();

// Serialize an object into the storage medium referenced by 'stream' object.
BinaryFormatter formatter = new BinaryFormatter();

// Serialize multiple objects into the stream
formatter.Serialize( stream, obOrders );
formatter.Serialize( stream, obProducts );
formatter.Serialize( stream, obCustomers );

// Return a stream with multiple objects
return stream;
}

private void DeSerializeMultipleObject(Stream stream)
{
// Construct a binary formatter
BinaryFormatter formatter = new BinaryFormatter();

// Deserialize the stream into object
Orders obOrders = (Orders)formatter.Deserialize( stream );
Products obProducts = (Products)formatter.Deserialize( stream );
Customers obCustomers = (Customer)formatter.Deserialize( stream );
}

اطلاعات کامل در مورد Serialization رو هم اینجا (http://www.diranieh.com/NETSerialization/BinarySerialization.htm) می تونی ببینی ...



حالا میخوام یه برنامه برای اون باشه قائدتا یکی هم برای کامپیوتر تا بتونم از سیستم به اون و بلعکس رشته یا حالا هرچی داده Rx-Tx کنم


"قائدتا" اونطوری نیست:بامزه:، بالعکسش میشه برنامه نویسی Embedded که استاداش جای دیگه هستن؛ باید native براش کد بنویسی، فکر کنم WCF یا Silverlight هم میتونی استفاده کنی، خلاصه اون دیگه بحثش مفصل تر از یکی دو تا پست هست، مثلاً :

Silverlight for Windows Embedded CE 6.0 (http://blogs.msdn.com/b/raffael/archive/2010/02/08/silverlight-for-windows-embedded-ce-6-0-first-sample-codes-stress-and-multiple-instances-of-a-control-in-separate-dll.aspx)