私は、モバイル通信と電子工学を勉強している成熟した学生であり、Java を学ぶことができますが、それは私が望むほど熟練していませんが、それがこの投稿の目的です。
私のデリマは、tcp接続を使用してワイヤレスからシリアルへのアダプター(Wiz6000)に接続するJavaプログラムを書きたいということですが、問題は、接続を作成する際に機能すると思われるコードがあることですが、USBを接続するとシリアル コンバーターをアダプターのシリアル出力に接続し、ハイパー ターミナルとのリンクを設定します。Wi-Fi からシリアル アダプターへのデータは受信されません。
私はこれまでに持っているコードを以下に含めました
import java.io.*;
import java.net.*;
public class Client1 {
// Modify this value (xxx.xxx.x.xxx) to the IP address you want your client to connect to (the server’s IP address)
static String hostString = "192.168.1.254";
// Modify this value (xxxxx) to the port number that the server is accepting connections on
static int portInt = 5000;
static Socket connectionSocket = null;
static PrintWriter out = null;
static BufferedReader in = null;
static String fromUserString = null;
static String fromServer = null;
static BufferedReader stdIn = null;
static String hostInetAddressString = null;
public int data;
public static void main(String[] args) {
try {
connectionSocket = new Socket(hostString, portInt);
hostString = connectionSocket.getInetAddress().toString();
out = new PrintWriter(connectionSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
// Get the Inet Address of the connectionSocket and store it in the hostInetAddress InetAddress variable and then cast the hostInetAddress to a String named hostInetAddressString
hostInetAddressString = connectionSocket.getInetAddress().toString();
System.out.println("Connected to server with Inet Address " + hostInetAddressString + " on port: " + connectionSocket.getPort() + "\n");
}
catch (Exception e) {
System.err.println(e);
System.exit(1);
}
// This is used to allow the client to receive input based on the program’s user pressing keys on their keyboard
/* stdIn = new BufferedReader(new InputStreamReader(System.in));
while (true) {
try {
if (fromUserString != null) {
int data=Integer.parseInt(fromUserString);
out.println(fromUserString);
fromUserString = null;
}
}
catch (Exception e) {
System.err.println(e);
break;
}
}*/
try
{
// Create a new instance of a OutputStreamWriter object
// attached to a ByteArrayOutputStream.
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out, "ASCII");
// Write to the output stream.
String s = "Hello World";
writer.write(s);
writer.flush();
// Display the contents of the ByteArrayOutputStream.
System.out.println(out.toString());
// Display the encoding being used.
System.out.println("encoding: " + writer.getEncoding());
// Close the OutputStreamWriter object.
writer.close();
}
catch (IOException ex)
{
System.out.println(ex.toString());
}
}
私は先週、Java ソケットのクライアントとサーバー、シリアル通信、およびシリアル化に関するさまざまなサイトを調べましたが、どの方法を使用すればよいかわかりません。
これの主な目的は、この wifi - シリアル アダプターに接続し、ユーザーから情報を取得して、wifi 接続を介して送信するアプリケーションを作成することです。一方、wifi - シリアルは、デジタル ディスプレイを制御する PCB に接続されています。 . 基板はアルバイト先の電機メーカー製で、シリアル接続でコマンドを受信できるように設定されています。
要するに、アプリをワイヤレス接続を介してデジタルディスプレイに接続し、表示するデータを送信する必要があります。