Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: EM_ver1 template FM_ver3_for_ARLISS FM_ver3_for_test
MU2.cpp
- Committer:
- Nerosho
- Date:
- 2019-07-16
- Revision:
- 0:48505968b10e
- Child:
- 1:dcb1eee964d5
File content as of revision 0:48505968b10e:
#include "MU2.h"
#include "mbed.h"
#include "stdint.h"
#include <string>
#include <sstream>
MU2::MU2(PinName tx,PinName rx) //MU2クラスのMU2という関数(コンストラクタ)の定義
{
_tx=tx;
_rx=rx;
}
/*MU2::MU2(PinName tx,PinName rx) : Serial(tx,rx){
}*/
void MU2::send(char Message[])
{
Serial MuPort(_tx,_rx);
Serial pc(USBTX,USBRX);
MuPort.baud(19200);
pc.baud(9600);
int index=0;
std::string send_data;
uint8_t last_data[]= {0x0d,0x0a}; //復帰、改行のアスキーコードを16進数で表す
int j=0;
while(Message[j]!='\0') {
j++;
}
index=j;//
send_data="@DT";
if(index<16) {
std::stringstream ss; //stiringstreamクラスのstd::hexマニュピレータを用いて変換。<sstream>のincludeが必要。
ss << std::hex << index ; //indexを16進数に変換
std::string str_ss = ss.str();
send_data += '0'+str_ss;
} else {
std::stringstream ss; //stiringstreamクラスのstd::hexマニュピレータを用いて変換。<sstream>のincludeが必要。
ss << std::hex << index ; //indexを16進数に変換
std::string str_ss = ss.str();
send_data += str_ss;
}
for(int n=0; n<index+1; n++) {
send_data += Message[n];
}
pc.printf("%s\n",send_data.c_str());
MuPort.printf("%s", send_data.c_str());//.c_str()でstring型のstrを変換
for(int i=0; i<2; i++) {
MuPort.putc(last_data[i]);
}
}